Closed
Description
The data argument can be used to pass a function to apply on the plot's data. It would be nice to be able to use the formula notation as well.
# works
ggplot(iris,aes(Sepal.Length,Sepal.Width)) +
geom_point(data = head)
# works as well
ggplot(iris,aes(Sepal.Length,Sepal.Width)) +
geom_point(data = function(x) head(x,10))
# doesn't
ggplot(iris,aes(Sepal.Length,Sepal.Width)) +
geom_point(data = ~head(.,10))
It should be a simple fix, either in layer
with something like if(inherits(data,"formula")) data <- rlang::as_function(data)
or in later in ggproto
after defining fortify.formula <- function(model, data, ...) model
to return the input as is done with fortify.function
, with the same but also testing for missing with something like if(!missing(data) && inherits(data,"formula")) data <- rlang::as_function(data)
trace(ggplot2:::layer,at =2,quote(
if(inherits(data,"formula")) data <- rlang::as_function(data)))
# now works
ggplot(iris,aes(Sepal.Length,Sepal.Width)) +
geom_point(data = ~head(.,10))