Skip to content

Commit e8cb599

Browse files
authored
Add ggplot_build() method for <ggplot_built> class (#5803)
* Add `ggplot_build.ggplot_built` method * small simplification in `get_guide_data()` * add news bullet
1 parent f7cf2af commit e8cb599

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ S3method(ggplot_add,list)
6767
S3method(ggplot_add,theme)
6868
S3method(ggplot_add,uneval)
6969
S3method(ggplot_build,ggplot)
70+
S3method(ggplot_build,ggplot_built)
7071
S3method(ggplot_gtable,ggplot_built)
7172
S3method(grid.draw,absoluteGrob)
7273
S3method(grid.draw,ggplot)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
alignment is not necessary (#5788).
7272
* `position_stack()` skips computation when all `x` values are unique and
7373
therefore stacking is not necessary (#5788).
74+
* A new `ggplot_build()` S3 method for <ggplot_built> classes was added, which
75+
returns input unaltered (@teunbrand, #5800).
7476

7577
# ggplot2 3.5.1
7678

R/guides-.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,7 @@ get_guide_data <- function(plot = get_last_plot(), aesthetic, panel = 1L) {
792792
check_string(aesthetic, allow_empty = FALSE)
793793
aesthetic <- standardise_aes_names(aesthetic)
794794

795-
if (!inherits(plot, "ggplot_built")) {
796-
plot <- ggplot_build(plot)
797-
}
795+
plot <- ggplot_build(plot)
798796

799797
if (!aesthetic %in% c("x", "y", "x.sec", "y.sec", "theta", "r")) {
800798
# Non position guides: check if aesthetic in colnames of key

R/plot-build.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ ggplot_build <- function(plot) {
3030
UseMethod('ggplot_build')
3131
}
3232

33+
#' @export
34+
ggplot_build.ggplot_built <- function(plot) {
35+
# This is a no-op
36+
plot
37+
}
38+
3339
#' @export
3440
ggplot_build.ggplot <- function(plot) {
3541
plot <- plot_clone(plot)

0 commit comments

Comments
 (0)