Dplyr + ggplot2: Plotting does not work on pipelines
I want to build a subset of my frame. I am working with dplyr and ggplot2. My code only works with version 1, not version 2 via pipeline. Who cares?
Version 1 (plotting works):
data <- dataset %>% filter(type=="type1")
ggplot(data, aes(x=year, y=variable)) + geom_line()
Version 2 with piping (plotting doesn't work):
data %>% filter(type=="type1") %>% ggplot(data, aes(x=year, y=variable)) + geom_line()
Mistake:
Error in ggplot.data.frame(., data, aes(x = year, :
Mapping should be created with aes or aes_string
Thank you for your help!
+2
source to share
3 answers