样本数据
dat <- structure(list(year = c(1980, 1981, 1982, 1983,
1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014),
mean.yield = c(1477.75648556686, 2082.78798946671, 1715.95287060116, 1694.91457026677, 1907.27741251624,
2299.77944711368, 1944.45457204444, 2332.23014830564, 1937.5072312786,
2301.36084850042, 2343.06974401949, 1897.71782987815, 3080.46183605819,
2825.77292866651, 2487.36584426788, 2534.75722997417, 3093.83332655611,
3163.41853753923, 2278.14084963203, 2639.86079242947, 2656.31404329224,
2351.89226744162, 2589.84639268955, 2692.39721213932, 2529.81158941515,
2902.34615481654, 2828.98931197959, 2762.30104195501, 2635.86326170991,
2568.74725294557, 2651.43758815608, 2703.25614409881, 2747.15308120843,
2821.89878248129, 2933.11693226163),
max.yld = c(1537.60708649028,
2171.29863798359, 1768.74854486813, 1789.36916707753, 1995.84210430024,
2354.06020071575, 2053.66394129283, 2412.0155018336, 1996.17829678252,
2396.51091307127, 2488.44909281084, 2032.74648952097, 3303.1998152912,
3053.26052365736, 2881.48366025859, 2637.90697074537, 3218.34312636772,
3280.09506675389, 2395.33412516854, 2840.67386500989, 2754.43088176743,
2604.96931198623, 2705.19033898282, 2796.10064804424, 2676.49124801024,
3070.48768976047, 3022.74601947175, 2856.77855666909, 2711.48801275607,
2614.20472283154, 2943.02001137724, 2922.93632378769, 2866.80927224562,
2875.28226346912, 3171.51986043323),
min.yld = c(1411.46865062697,
1987.25224650323, 1635.03389892575, 1551.90596491633, 1787.98499366881,
2207.44878742555, 1845.66299576147, 2243.54678049618, 1873.44546707733,
2219.53361649614, 2107.52355423417, 1710.47189603077, 2819.77978390805,
2552.28608023919, 2088.3687315005, 2330.72467231082, 2992.51321436047,
3033.95006763494, 2124.61291993433, 2456.804932555, 2439.9048945899,
2043.10726300988, 2347.74223494172, 2467.56879062196, 2276.01009074814,
2789.30766856972, 2750.67648303084, 2613.06512489394, 2472.29245440674,
2500.27445852508, 2504.67728857491, 2531.46080829744, 2600.35290182939,
2704.84177339319, 2587.00260848201)), row.names = c(NA, -35L), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), vars = "mun.id", drop = TRUE, indices = list(
0:34), group_sizes = 35L, biggest_group_size = 35L, labels = structure(list(
mun.id = 1100031L), row.names = c(NA, -1L), class = "data.frame", vars = "mun.id", drop = TRUE))
数据有四列:年,平均产量,最大产量和最小产量。我绘制了平均产量,如下所示:
ggplot(dat, aes(x = year, y = mean.yield)) + geom_line() + geom_point() + theme_bw()
对于每个点,我如何将最大产量和最小产量作为晶须相加。
答案 0 :(得分:2)
使用linerange()
ggplot(dat, aes(x = year, y = mean.yield)) +
geom_point() +
geom_line() +
geom_linerange(aes(ymin = min.yld, ymax= max.yld), colour = "blue") +
theme_bw()
答案 1 :(得分:2)
geom_ribbon()
ggplot(temp, aes(x = year)) +
geom_ribbon(aes(ymin = min.yld,
ymax = max.yld),
fill = "grey") +
geom_line(aes(y = mean.yield), color = "red") +
geom_point(aes(y = mean.yield), color = "red") +
theme_bw()
答案 2 :(得分:2)
带有geom_errorbar
ggplot(dat, aes(x = year, y = mean.yield)) +
geom_line() +
geom_point() +
geom_errorbar(aes(ymin = min.yld, ymax= max.yld), width=0.5) +
theme_bw()
答案 3 :(得分:1)