So, I'am trying to use the filter()
with ggplot()
in R with this code:
LIST %>% filter(LIST %in% YEAR==c("2019","2020")) %>% group_by(`YEAR`, `Month`,`Line`,UF,`Segment`,`Fai`) %>% summarise(sum(qtd))%>% ggplot() + geom_col(aes(x=YEAR, y=`sum(qtd)`))
Or this one:
LIST %>% group_by(`YEAR`, `Month`,`Line`,UF,`Segment`,`Fai`) %>% summarise(sum(qtd)) %>% filter(LIST %in% YEAR==c("2019","2020")) %>% ggplot() + geom_col(aes(x=YEAR, y=`sum(qtd)`))
For both of them I receive the same error:
Error: Problem with `filter()` input `..1`.
i Input `..1` is `LIST %in% YEAR == c("2019", "2020")`.
x Input `..1` must be of size 12396 or 1, not size 33.
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning message:
In LIST %in% YEAR == c("2019", "2020") :
longer object length is not a multiple of shorter object length
Only as information, this database has 33 columns and 12396 lines
This code works without the filter()
function on it, but them I need to filter and save the database before doing the plot, so I really would like to understand the why it isn't working
The code with filter()
used before de plot code
LIST<-filter(LIST %in% YEAR==c("2019","2020"))
LIST %>% group_by(`YEAR`, `Month`,`Line`,UF,`Segment`,`Fai`) %>% summarise(sum(qtd))%>% ggplot() + geom_col(aes(x=YEAR, y=`sum(qtd)`))