【发布时间】:2015-11-07 16:26:58
【问题描述】:
我想绘制我的数据框的一个子集。我正在使用 dplyr 和 ggplot2。我的代码仅适用于版本 1,而不适用于通过管道的版本 2。有什么不同?
版本 1(正在绘图):
data <- dataset %>% filter(type=="type1")
ggplot(data, aes(x=year, y=variable)) + geom_line()
带有管道的版本 2(绘图不起作用):
data %>% filter(type=="type1") %>% ggplot(data, aes(x=year, y=variable)) + geom_line()
错误:
Error in ggplot.data.frame(., data, aes(x = year, :
Mapping should be created with aes or aes_string
感谢您的帮助!
【问题讨论】:
-
也许问题是在第二个
ggplot中你必须使用.而不是data。 -
这很快。谢谢!
-
请不要将答案发布为对您问题的编辑,将其发布为答案(您可能需要等待一段时间)...