oh, awesome! Thanks for all the responses everyone. @knm hit it on the head when she suggested ggplot(mpg, aes(x=hwy,y=displ,label=model))+geom_point()+geom_text(data=function(x){filter(x,hwy>40)})
, and @nick made it look nicer by using .
.
To enumerate, I've been doing something like the following, where I create an intermediate tmp
dataframe:
tmp <- mpg %>%
filter(<something>)
tmp %>%
ggplot(aes(x=hwy, y=displ, label=model)) +
geom_point() +
geom_text(tmp >% filter(hwy > 40))
But wanted to see if I could be super lazy and do it all in a single string of pipes. So this would totally work:
mpg %>%
filter(<something>) %>%
ggplot(aes(x=hwy, y=displ, label=model)) +
geom_point() +
geom_text(data = . %>% filter(hwy > 40))
@nick -- to as a followup, is the .
(dot) object standard in R and can I use it to reference inherited functions in other objects? Or it that something tidyverse specific?
Thanks again!