Skip to content

Commit 2d3c1c6

Browse files
committed
Merge branch 'main' into violin_data_quantiles
2 parents 7cabd35 + 628d7ab commit 2d3c1c6

28 files changed

+558
-59
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ Collate:
274274
'theme.R'
275275
'theme-defaults.R'
276276
'theme-current.R'
277+
'theme-sub.R'
277278
'utilities-break.R'
278279
'utilities-grid.R'
279280
'utilities-help.R'

NAMESPACE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,17 @@ export(theme_linedraw)
725725
export(theme_minimal)
726726
export(theme_replace)
727727
export(theme_set)
728+
export(theme_sub_axis)
729+
export(theme_sub_axis_bottom)
730+
export(theme_sub_axis_left)
731+
export(theme_sub_axis_right)
732+
export(theme_sub_axis_top)
733+
export(theme_sub_axis_x)
734+
export(theme_sub_axis_y)
735+
export(theme_sub_legend)
736+
export(theme_sub_panel)
737+
export(theme_sub_plot)
738+
export(theme_sub_strip)
728739
export(theme_test)
729740
export(theme_transparent)
730741
export(theme_update)

NEWS.md

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

3+
* New function family for setting parts of a theme. For example, you can now use
4+
`theme_sub_axis(line, text, ticks, ticks.length, line)` as a substitute for
5+
`theme(axis.line, axis.text, axis.ticks, axis.ticks.length, axis.line)`. This
6+
should allow slightly terser and more organised theme declarations
7+
(@teunbrand, #5301).
8+
* `scale_{x/y}_discrete(continuous.limits)` is a new argument to control the
9+
display range of discrete scales (@teunbrand, #4174, #6259).
10+
* `geom_ribbon()` now appropriately warns about, and removes, missing values
11+
(@teunbrand, #6243).
312
* `guide_*()` can now accept two inside legend theme elements:
413
`legend.position.inside` and `legend.justification.inside`, allowing inside
514
legends to be placed at different positions. Only inside legends with the same
@@ -250,6 +259,8 @@
250259
* `geom_abline()` clips to the panel range in the vertical direction too
251260
(@teunbrand, #6086).
252261
* Added `panel.widths` and `panel.heights` to `theme()` (#5338, @teunbrand).
262+
* Standardised the calculation of `width`, which are now implemented as
263+
aesthetics (@teunbrand, #2800).
253264

254265
# ggplot2 3.5.1
255266

R/coord-radial.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' @param end Position from 12 o'clock in radians where plot ends, to allow
55
#' for partial polar coordinates. The default, `NULL`, is set to
66
#' `start + 2 * pi`.
7-
#' @param expand If `TRUE`, the default, adds a small expansion factor the
7+
#' @param expand If `TRUE`, the default, adds a small expansion factor to
88
#' the limits to prevent overlap between data and axes. If `FALSE`, limits
99
#' are taken directly from the scale.
1010
#' @param r.axis.inside One of the following:

R/geom-bar.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ GeomBar <- ggproto("GeomBar", GeomRect,
130130
# limits, not just those for which x and y are outside the limits
131131
non_missing_aes = c("xmin", "xmax", "ymin", "ymax"),
132132

133-
default_aes = aes(!!!GeomRect$default_aes, width = NULL),
133+
default_aes = aes(!!!GeomRect$default_aes, width = 0.9),
134134

135135
setup_params = function(data, params) {
136136
params$flipped_aes <- has_flipped_aes(data, params)
@@ -139,14 +139,13 @@ GeomBar <- ggproto("GeomBar", GeomRect,
139139

140140
extra_params = c("just", "na.rm", "orientation"),
141141

142-
setup_data = function(data, params) {
142+
setup_data = function(self, data, params) {
143143
data$flipped_aes <- params$flipped_aes
144144
data <- flip_data(data, params$flipped_aes)
145-
data$width <- data$width %||%
146-
params$width %||% (min(vapply(
147-
split(data$x, data$PANEL, drop = TRUE),
148-
resolution, numeric(1), zero = FALSE
149-
)) * 0.9)
145+
data <- compute_data_size(
146+
data, size = params$width,
147+
default = self$default_aes$width, zero = FALSE
148+
)
150149
data$just <- params$just %||% 0.5
151150
data <- transform(data,
152151
ymin = pmin(y, 0), ymax = pmax(y, 0),

R/geom-boxplot.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,21 @@ geom_boxplot <- function(mapping = NULL, data = NULL,
236236
#' @export
237237
GeomBoxplot <- ggproto("GeomBoxplot", Geom,
238238

239-
# need to declare `width` here in case this geom is used with a stat that
240-
# doesn't have a `width` parameter (e.g., `stat_identity`).
241-
extra_params = c("na.rm", "width", "orientation", "outliers"),
239+
extra_params = c("na.rm", "orientation", "outliers"),
242240

243241
setup_params = function(data, params) {
244242
params$flipped_aes <- has_flipped_aes(data, params)
245243
params
246244
},
247245

248-
setup_data = function(data, params) {
246+
setup_data = function(self, data, params) {
249247
data$flipped_aes <- params$flipped_aes
250248
data <- flip_data(data, params$flipped_aes)
251-
data$width <- data$width %||%
252-
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
253-
249+
data <- compute_data_size(
250+
data, params$width,
251+
default = self$default_aes$width,
252+
zero = FALSE, discrete = TRUE
253+
)
254254
if (isFALSE(params$outliers)) {
255255
data$outliers <- NULL
256256
}
@@ -389,7 +389,8 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
389389
weight = 1, colour = from_theme(col_mix(ink, paper, 0.2)),
390390
fill = from_theme(paper), size = from_theme(pointsize),
391391
alpha = NA, shape = from_theme(pointshape), linetype = from_theme(bordertype),
392-
linewidth = from_theme(borderwidth)
392+
linewidth = from_theme(borderwidth),
393+
width = 0.9
393394
),
394395

395396
required_aes = c("x|y", "lower|xlower", "upper|xupper", "middle|xmiddle", "ymin|xmin", "ymax|xmax"),

R/geom-dotplot.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,16 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
194194
alpha = NA,
195195
stroke = from_theme(borderwidth * 2),
196196
linetype = from_theme(linetype),
197-
weight = 1
197+
weight = 1,
198+
width = 0.9
198199
),
199200

200-
setup_data = function(data, params) {
201-
data$width <- data$width %||%
202-
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
201+
setup_data = function(self, data, params) {
202+
data <- compute_data_size(
203+
data, params$width,
204+
default = self$default_aes$width,
205+
zero = FALSE, discrete = TRUE
206+
)
203207

204208
# Set up the stacking function and range
205209
if (is.null(params$stackdir) || params$stackdir == "up") {

R/geom-errorbar.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ GeomErrorbar <- ggproto("GeomErrorbar", Geom,
6262
colour = from_theme(ink),
6363
linewidth = from_theme(linewidth),
6464
linetype = from_theme(linetype),
65-
width = 0.5,
65+
width = 0.9,
6666
alpha = NA
6767
),
6868

@@ -76,17 +76,21 @@ GeomErrorbar <- ggproto("GeomErrorbar", Geom,
7676

7777
extra_params = c("na.rm", "orientation"),
7878

79-
setup_data = function(data, params) {
79+
setup_data = function(self, data, params) {
8080
data$flipped_aes <- params$flipped_aes
8181
data <- flip_data(data, params$flipped_aes)
82-
data$width <- data$width %||%
83-
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
82+
data <- compute_data_size(
83+
data, params$width,
84+
default = self$default_aes$width,
85+
zero = FALSE, discrete = TRUE
86+
)
8487
data <- transform(data,
8588
xmin = x - width / 2, xmax = x + width / 2, width = NULL
8689
)
8790
flip_data(data, params$flipped_aes)
8891
},
8992

93+
# Note: `width` is vestigial
9094
draw_panel = function(self, data, panel_params, coord, lineend = "butt",
9195
width = NULL, flipped_aes = FALSE) {
9296
data <- check_linewidth(data, snake_class(self))

R/geom-ribbon.R

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,31 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
126126

127127
draw_key = draw_key_polygon,
128128

129-
handle_na = function(data, params) {
129+
handle_na = function(self, data, params) {
130+
131+
vars <- vapply(
132+
strsplit(self$required_aes, "|", fixed = TRUE),
133+
`[[`, i = 1, character(1)
134+
)
135+
if (params$flipped_aes || any(data$flipped_aes) %||% FALSE) {
136+
vars <- switch_orientation(vars)
137+
}
138+
vars <- c(vars, self$non_missing_aes)
139+
140+
missing <- detect_missing(data, vars, finite = FALSE)
141+
if (!any(missing)) {
142+
return(data)
143+
}
144+
# We're rearranging groups to account for missing values
145+
data$group <- vec_identify_runs(data_frame0(missing, data$group))
146+
data <- vec_slice(data, !missing)
147+
148+
if (!params$na.rm) {
149+
cli::cli_warn(
150+
"Removed {sum(missing)} row{?s} containing missing values or values \\
151+
outside the scale range ({.fn {snake_class(self)}})."
152+
)
153+
}
130154
data
131155
},
132156

@@ -135,7 +159,6 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
135159
flipped_aes = FALSE, outline.type = "both") {
136160
data <- check_linewidth(data, snake_class(self))
137161
data <- flip_data(data, flipped_aes)
138-
if (na.rm) data <- data[stats::complete.cases(data[c("x", "ymin", "ymax")]), ]
139162
data <- data[order(data$group), ]
140163

141164
# Check that aesthetics are constant

R/geom-tile.R

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,20 @@ geom_tile <- function(mapping = NULL, data = NULL,
109109
GeomTile <- ggproto("GeomTile", GeomRect,
110110
extra_params = c("na.rm"),
111111

112-
setup_data = function(data, params) {
113-
114-
data$width <- data$width %||% params$width %||%
115-
stats::ave(data$x, data$PANEL, FUN = function(x) resolution(x, FALSE, TRUE))
116-
data$height <- data$height %||% params$height %||%
117-
stats::ave(data$y, data$PANEL, FUN = function(y) resolution(y, FALSE, TRUE))
112+
setup_data = function(self, data, params) {
118113

114+
data <- compute_data_size(
115+
data, params$width,
116+
default = self$default_aes$width,
117+
panels = "by", target = "width",
118+
zero = FALSE, discrete = TRUE
119+
)
120+
data <- compute_data_size(
121+
data, params$height,
122+
default = self$default_aes$height,
123+
panels = "by", target = "height",
124+
zero = FALSE, discrete = TRUE
125+
)
119126
transform(data,
120127
xmin = x - width / 2, xmax = x + width / 2, width = NULL,
121128
ymin = y - height / 2, ymax = y + height / 2, height = NULL
@@ -127,7 +134,7 @@ GeomTile <- ggproto("GeomTile", GeomRect,
127134
colour = NA,
128135
linewidth = from_theme(0.4 * borderwidth),
129136
linetype = from_theme(bordertype),
130-
alpha = NA, width = NA, height = NA
137+
alpha = NA, width = 1, height = 1
131138
),
132139

133140
required_aes = c("x", "y"),

0 commit comments

Comments
 (0)