Is there a method of filtering within ggplot
itself? That is, say I want to do this
p <- ggplot(iris, aes(x = Sepal.Width, y = Sepal
apparently layers now accept a function as data argument, so you could use that
pick <- function(condition){
function(d) d %>% filter_(condition)
}
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, species)) +
geom_point(size = 4, shape = 4) +
geom_point(data = pick(~Species == "setosa"), colour = "red") +
geom_point(data = pick(~Species == "versicolor"), shape = 5)