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

Add ggplot_build() method for <ggplot_built> class #5803

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ S3method(ggplot_add,list)
S3method(ggplot_add,theme)
S3method(ggplot_add,uneval)
S3method(ggplot_build,ggplot)
S3method(ggplot_build,ggplot_built)
S3method(ggplot_gtable,ggplot_built)
S3method(grid.draw,absoluteGrob)
S3method(grid.draw,ggplot)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

# ggplot2 (development version)

* A new `ggplot_build()` S3 method for <ggplot_built> classes was added, which
returns input unaltered (@teunbrand, #5800).
* `coord_map()` and `coord_polar()` throw informative warnings when used
with the guide system (#5707).
* When passing a function to `stat_contour(breaks)`, that function is used to
Expand Down
4 changes: 1 addition & 3 deletions R/guides-.R
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,7 @@ get_guide_data <- function(plot = last_plot(), aesthetic, panel = 1L) {
check_string(aesthetic, allow_empty = FALSE)
aesthetic <- standardise_aes_names(aesthetic)

if (!inherits(plot, "ggplot_built")) {
plot <- ggplot_build(plot)
}
plot <- ggplot_build(plot)

if (!aesthetic %in% c("x", "y", "x.sec", "y.sec", "theta", "r")) {
# Non position guides: check if aesthetic in colnames of key
Expand Down
6 changes: 6 additions & 0 deletions R/plot-build.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ ggplot_build <- function(plot) {
UseMethod('ggplot_build')
}

#' @export
ggplot_build.ggplot_built <- function(plot) {
# This is a no-op
plot
}

#' @export
ggplot_build.ggplot <- function(plot) {
plot <- plot_clone(plot)
Expand Down