dplyr+;ggplot2:通过管道打印不起作用
我想绘制数据帧的一个子集。我正在与dplyr和ggplot2合作。我的代码仅适用于版本1,而不是通过管道的版本2。有什么区别 版本1(正在打印): 错误:dplyr+;ggplot2:通过管道打印不起作用,r,ggplot2,dplyr,R,Ggplot2,Dplyr,我想绘制数据帧的一个子集。我正在与dplyr和ggplot2合作。我的代码仅适用于版本1,而不是通过管道的版本2。有什么区别 版本1(正在打印): 错误: Error in ggplot.data.frame(., data, aes(x = year, : Mapping should be created with aes or aes_string 谢谢你的帮助 在使用管道输入时,如果您重新输入数据名,如我在下面用粗体显示的那样,函数会混淆参数序列 data%>%filter(typ
Error in ggplot.data.frame(., data, aes(x = year, :
Mapping should be created with aes or aes_string
谢谢你的帮助 在使用管道输入时,如果您重新输入数据名,如我在下面用粗体显示的那样,函数会混淆参数序列
data%>%filter(type==“type1”)%%>%ggplot(***data***,aes(x=year,y=variable))+geom_line()
希望它对您有用。版本2的解决方案:a点。而不是数据:
data %>% filter(type=="type1") %>% ggplot(., aes(x=year, y=variable)) + geom_line()
我通常这样做,这也省去了
:
library(dplyr)
library(ggplot2)
mtcars %>%
filter(cyl == 4) %>%
ggplot +
aes(
x = disp,
y = mpg
) +
geom_point()
可能问题是在第二个
ggplot
中,您必须使用
而不是数据
。这很快。谢谢请不要将答案作为编辑发布到您的问题中,将其作为答案发布(您可能需要等待一段时间)……从技术上讲,您也可以省略
,如iris%>%过滤器(物种==“setosa”)%%>%ggplot(aes(x=Sepal.Width,y=Sepal.Length))+geom_point()
,但使用显式
data %>% filter(type=="type1") %>% ggplot(., aes(x=year, y=variable)) + geom_line()
library(dplyr)
library(ggplot2)
mtcars %>%
filter(cyl == 4) %>%
ggplot +
aes(
x = disp,
y = mpg
) +
geom_point()