ggplot-如何绘制带有多个DATE列的年份的多行?

时间:2018-12-19 10:58:23

标签: r ggplot2

我有一个像这样的数据框: enter image description here

....

我想用这样的多条线做一个时间序列(在Excel中,我只是按插入线形图,它会自动产生它):

enter image description here

我似乎无法在R中复制它。我已经在线浏览了示例,并且大多数示例都引用了我没有的日期列。

ggplot(test_data, aes(date)) + 
  geom_line(aes(y = var0, colour = "var0")) + 
  geom_line(aes(y = var1, colour = "var1"))

我知道我可以调整数据框的形状以使其正常工作,但是我很想知道是否可以使用我所使用的格式,因为大多数时候我的年度数据都采用该格式。

非常感谢


根据要求,请在下面找到dput(head(df))的结果:

structure(list(Area = structure(c(4L, 3L, 1L, 2L), .Label = c("C", 
"D", "B", "A"), class = "factor"), 
    X1986 = c(1341.570138, 1620.688757, 2680.889319, 4920.591143
    ), X1987 = c(1385.663221, 1620.160073, 2479.27127, 4596.138313
    ), X1988 = c(1395.433255, 1661.706746, 2400.465528, 4250.365569
    ), X1989 = c(1492.712373, 1542.9032, 2236.28018, 4279.23273
    ), X1990 = c(1529.197126, 1482.805753, 2183.830952, 4015.431105
    ), X1991 = c(1486.809251, 1543.681736, 1881.666789, 4154.941261
    ), X1992 = c(1665.658322, 1526.193116, 1922.40109, 3298.035175
    ), X1993 = c(1799.433266, 1497.722616, 1841.208587, 3526.14653
    ), X1994 = c(1869.644613, 1554.724915, 1707.598555, 3106.392358
    ), X1995 = c(1920.74671, 1509.89973, 2177.340672, 3070.228331
    ), X1996 = c(1879.792451, 1472.886158, 2070.35068, 3200.805134
    ), X1997 = c(1894.511281, 1470.34572, 1927.248891, 3293.688282
    ), X1998 = c(1874.599076, 1524.692651, 1929.403696, 3007.227902
    ), X1999 = c(1951.498183, 1619.715494, 2102.690295, 3180.634055
    ), X2000 = c(2072.850287, 1746.999317, 2278.218546, 3066.832658
    ), X2001 = c(2313.951267, 1998.104375, 2407.485325, 2788.399389
    ), X2002 = c(2575.416785, 2150.81032, 2702.401897, 3616.430145
    ), X2003 = c(2927.231972, 2157.521573, 2773.03073, 3468.88003
    ), X2004 = c(3038.569944, 2276.403729, 2354.639334, 3250.563196
    ), X2005 = c(3530.318897, 2370.761001, 2610.542326, 2758.100064
    ), X2006 = c(3599.260498, 2489.866669, 2474.34232, 2536.439714
    ), X2007 = c(3195.202342, 2624.214323, 2388.827425, 2492.537494
    ), X2008 = c(3430.836114, 2549.301835, 2497.11319, 2258.860682
    ), X2009 = c(3575.208306, 2688.118135, 2746.287982, 1959.876393
    ), X2010 = c(3602.174536, 2556.665341, 2583.022716, 1859.293137
    ), X2011 = c(3555.596225, 2476.993102, 2720.898331, 1415.734351
    ), X2012 = c(3382.458554, 2350.612102, 2807.557493, 1551.489001
    ), X2013 = c(3697.355873, 2397.072097, 3116.08937, 1582.046713
    ), X2014 = c(3549.650832, 2417.26585, 3140.590925, 1755.76343
    ), X2015 = c(3487.7464, 2308.1276, 3208.6858, 1710.1406), 
    X2016 = c(3406L, 2248L, 3323L, 1623L)), row.names = c(NA, 
4L), class = "data.frame")

0 个答案:

没有答案