我想绘制数据框的一个子集。我正在使用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
。 - SabDeM