尝试向ggplot添加行:美学必须是长度1或与数据相同

时间:2017-06-06 17:34:19

标签: r ggplot2

我正在尝试向ggplot添加一行,但是我收到错误:

Error: Aesthetics must be either length 1 or the same as the data (8): x, y, group, colour

这是一个复制我的问题的代码。我首先绘制两个分组的行,然后想要添加另一个。

a = data.frame(year = c(1:4,1:4), def = c(rep("xx",4),rep("yy",4)), valu = c(3,4,7,8,14,17,11,13))
b = data.frame(year = c(1:4), valu = c(1,9,1,9))
dev.new()
g = ggplot(a, aes(x = year, y = valu, group = def, color = def)) + geom_line()
g = g + geom_line(aes(x = b$year, y = b$valu))
g

感谢任何帮助,谢谢!

0 个答案:

没有答案