I'm trying to include subsets directly in the geom
argument in ggplot, and am trying to understand what seems to be inconsistent behavior.
If I use data = . %>% filter()
it works, but if I try to use data = filter(.)
I get an error message. Outside of a ggplot flow those two syntaxes are normally interchangeable, so what's going on here?
library(tidyverse)
# piping in, works
ggplot(data = cars, aes(x = speed, y = dist)) +
geom_point(data = . %>% filter(speed > 10))
# '.' in function, error: "object '.' not found"
ggplot(data = cars, aes(x = speed, y = dist)) +
geom_point(data = filter(. , speed > 10))