I want to inherit the data from within a ggplot call and not have to reference it again. So for example in my code below, I reference to mtcars twice, but I want it to "inherit" the data within my function.
myfun <- function(data, x){
if(nrow(data) > x){
return(theme_light())
}
else{
return(theme_dark())
}
}
ggplot(mtcars, aes(cyl, disp)) + geom_point() + myfun(mtcars, 5)
So instead I would put
ggplot(mtcars, aes(cyl, disp)) + geom_point() + myfun(5)