Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support formula notation in data argument ? #3138

Closed
moodymudskipper opened this issue Feb 13, 2019 · 2 comments
Closed

Support formula notation in data argument ? #3138

moodymudskipper opened this issue Feb 13, 2019 · 2 comments
Labels
Milestone

Comments

@moodymudskipper
Copy link

@moodymudskipper moodymudskipper commented Feb 13, 2019

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))
@yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Feb 13, 2019

I'm going to make this happen after #3038.

@lock
Copy link

@lock lock bot commented Oct 21, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Oct 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants