Skip to content

Commit 5c79bc7

Browse files
authored
layer_*() functions default to plot = last_plot() (#5187)
* Set `last_plot()` as default `plot` argument in layer* functions * Add NEWS bullet
1 parent 9e9b49b commit 5c79bc7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* The `layer_data()`, `layer_scales()` and `layer_grob()` now have the default
4+
`plot = last_plot()` (@teunbrand, #5166).
35
* To prevent changing the plotting order, `stat_sf()` is now computed per panel
46
instead of per group (@teunbrand, #4340).
57
* ggplot2 now uses `scales::DiscreteRange` and `scales::ContinuousRange`, which

R/plot-build.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ ggplot_build.ggplot <- function(plot) {
111111

112112
#' @export
113113
#' @rdname ggplot_build
114-
layer_data <- function(plot, i = 1L) {
114+
layer_data <- function(plot = last_plot(), i = 1L) {
115115
ggplot_build(plot)$data[[i]]
116116
}
117117

118118
#' @export
119119
#' @rdname ggplot_build
120-
layer_scales <- function(plot, i = 1L, j = 1L) {
120+
layer_scales <- function(plot = last_plot(), i = 1L, j = 1L) {
121121
b <- ggplot_build(plot)
122122

123123
layout <- b$layout$layout
@@ -131,7 +131,7 @@ layer_scales <- function(plot, i = 1L, j = 1L) {
131131

132132
#' @export
133133
#' @rdname ggplot_build
134-
layer_grob <- function(plot, i = 1L) {
134+
layer_grob <- function(plot = last_plot(), i = 1L) {
135135
b <- ggplot_build(plot)
136136

137137
b$plot$layers[[i]]$draw_geom(b$data[[i]], b$layout)

0 commit comments

Comments
 (0)