Skip to content

Make layer() accept formula notation for data argument #3245

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

Conversation

yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Apr 13, 2019

Fix #3138

data is processed by fortify() once and stored in layer. Then, if it's a function, it's applied to the plot data when the plot is built,

ggplot2/R/layer.r

Lines 191 to 192 in 475042e

} else if (is.function(self$data)) {
data <- self$data(plot_data)

So, all we have to do is to define a fortify() method that converts a formula to a function.

Usages

devtools::load_all("~/repo/R/ggplot2/")
#> Loading ggplot2

ggplot(iris, aes(Sepal.Length, Sepal.Width)) + 
  geom_point(data = ~ head(., 10))

Created on 2019-04-13 by the reprex package (v0.2.1)

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasp85
Copy link
Member

There's a dependency on #3242... If you merge that one first and then update this to remove the rlang namespacing it's all good :-)

@yutannihilation
Copy link
Member Author

Sure, thanks!

man/theme.Rd Outdated
@@ -251,15 +251,20 @@ p1 + theme(
)

# Axes ----------------------------------------------------------------------
# Change styles of axes texts and lines
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems these diffs of theme.Rd come from #2934. It might be better to create a separate PR, but I let this included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that PR also missed to generate a new vdiffr reference image. Do you have the time to create a separate PR that includes the updated .Rd file and the missing image? That would probably be the best approach.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sure. Will do.

@yutannihilation yutannihilation merged commit 8164df2 into tidyverse:master Apr 24, 2019
@yutannihilation yutannihilation deleted the feature/layer-data-lambda-notation branch April 24, 2019 15:35
@lock
Copy link

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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support formula notation in data argument ?
3 participants