I have been happily using the |>
version of pipes since it was made a part of "base" r. However, I just encountered a situation where it did not work and I had to revert back to the %>%
pipe code. I don't know why one would work and one wouldn't and I'm curious how I am properly supposed to pass a dataframe to ggplot within pipes.
Code that DIDN'T work:
dataframe |> ggplot( aes(x = x_variable, y = y_variable) ) + geom_col(data = . |> filter(y_variable >= 0), fill = "red") + geom_col(data = . |> filter(y_variable <= 0), fill = "blue")
Code that DID work:
dataframe |> ggplot( aes(x = x_variable, y = y_variable) ) + geom_col(data = . %>% filter(y_variable >= 0), fill = "red") + geom_col(data = . %>% filter(y_variable <= 0), fill = "blue")