我试图使用以下数据制作堆积线图(称为Test.xls):
Test <- read.table(text = "
Date A B C D
1002EST 0.225164194 0.089942967 0.684289684 0.000603155
1007EST 0.606697971 0.375931286 0.015410986 0.001959757
1012EST 0.745430542 0.240069576 0.01186502 0.002634862
1017EST 0.586552052 0.253384789 0.159091468 0.000971692
1022EST 0.719846808 0.085252303 0.193054704 0.001846186
1106EST 0.908801738 0.075007121 0.015196251 0.00099489
1111EST 0.901317416 0.083624883 0.011020257 0.004037444
1116EST 0.838439325 0.116000974 0.042570946 0.002988756
1121EST 0.822848944 0.14935052 0.024948372 0.002852164
1126EST 0.878149037 0.107215826 0.011199368 0.003435768
1206EST 0.806550999 0.127171158 0.062039302 0.00423854",
header = TRUE, stringsAsFactors = FALSE)
我使用RStudio的“import dataset”选项导入数据。 R绘图代码如下:
library(reshape2)
Test_melt <- melt(Test, "Date")
library(ggplot2)
ggplot(Test_melt, aes(x = Date, y = value, fill = variable)) +
geom_area(position = 'stack')
但是我发现我的脚本没有生成任何图,如下所示: Rplot
我怎么能解决这个问题?
答案 0 :(得分:2)
尝试添加group = variable
,无需position = "stack"
:
ggplot(Test_melt, aes(Date, value)) + geom_area(aes(fill = variable, group = variable))
答案 1 :(得分:2)