Skip to content

Commit 3f67f03

Browse files
committed
resolve merge conflict
Merge branch 'main' into hierarchical_theme_lookup # Conflicts: # R/theme.R
2 parents 4fd2ce3 + e727e2b commit 3f67f03

File tree

217 files changed

+3768
-1472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+3768
-1472
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ Collate:
242242
'scales-.R'
243243
'stat-align.R'
244244
'stat-bin.R'
245+
'stat-summary-2d.R'
245246
'stat-bin2d.R'
246247
'stat-bindot.R'
247248
'stat-binhex.R'
@@ -263,7 +264,6 @@ Collate:
263264
'stat-smooth-methods.R'
264265
'stat-smooth.R'
265266
'stat-sum.R'
266-
'stat-summary-2d.R'
267267
'stat-summary-bin.R'
268268
'stat-summary-hex.R'
269269
'stat-summary.R'
@@ -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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ S3method(c,mapped_discrete)
2020
S3method(drawDetails,zeroGrob)
2121
S3method(element_grob,element_blank)
2222
S3method(element_grob,element_line)
23+
S3method(element_grob,element_point)
24+
S3method(element_grob,element_polygon)
2325
S3method(element_grob,element_rect)
2426
S3method(element_grob,element_text)
2527
S3method(format,ggproto)
@@ -346,6 +348,8 @@ export(element_blank)
346348
export(element_geom)
347349
export(element_grob)
348350
export(element_line)
351+
export(element_point)
352+
export(element_polygon)
349353
export(element_rect)
350354
export(element_render)
351355
export(element_text)
@@ -725,6 +729,17 @@ export(theme_linedraw)
725729
export(theme_minimal)
726730
export(theme_replace)
727731
export(theme_set)
732+
export(theme_sub_axis)
733+
export(theme_sub_axis_bottom)
734+
export(theme_sub_axis_left)
735+
export(theme_sub_axis_right)
736+
export(theme_sub_axis_top)
737+
export(theme_sub_axis_x)
738+
export(theme_sub_axis_y)
739+
export(theme_sub_legend)
740+
export(theme_sub_panel)
741+
export(theme_sub_plot)
742+
export(theme_sub_strip)
728743
export(theme_test)
729744
export(theme_transparent)
730745
export(theme_update)

NEWS.md

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

3+
* New parameters for `geom_label()` (@teunbrand and @steveharoz, #5365):
4+
* The `linewidth` aesthetic is now applied and replaces the `label.size`
5+
argument.
6+
* The `linetype` aesthetic is now applied.
7+
* New `border.colour` argument to set the colour of borders.
8+
* New `text.colour` argument to set the colour of text.
9+
* New `element_point()` and `element_polygon()` that can be given to
10+
`theme(point, polygon)` as an extension point (@teunbrand, #6248).
11+
* Turned off fallback for `size` to `linewidth` translation in
12+
`geom_bar()`/`geom_col()` (#4848).
13+
* `coord_radial()` now displays no axis instead of throwing an error when
14+
a scale has no breaks (@teunbrand, #6271).
15+
* The `fatten` argument has been deprecated in `geom_boxplot()`,
16+
`geom_crossbar()` and `geom_pointrange()` (@teunbrand, #4881).
17+
* Axis labels are now preserved better when using `coord_sf(expand = TRUE)` and
18+
graticule lines are straight but do not meet the edge (@teunbrand, #2985).
19+
* Attempt to boost detail in `coord_polar()` and `coord_radial()` near the
20+
center (@teunbrand, #5023)
21+
* Scale names, guide titles and aesthetic labels can now accept functions
22+
(@teunbrand, #4313)
23+
* Binned scales with zero-width data expand the default limits by 0.1
24+
(@teunbrand, #5066)
25+
* New default `geom_qq_line(geom = "abline")` for better clipping in the
26+
vertical direction. In addition, `slope` and `intercept` are new computed
27+
variables in `stat_qq_line()` (@teunbrand, #6087).
28+
* Position adjustments can now have auxiliary aesthetics (@teunbrand).
29+
* `position_nudge()` gains `nudge_x` and `nudge_y` aesthetics (#3026, #5445).
30+
* `position_dodge()` gains `order` aesthetic (#3022, #3345)
31+
* More stability for vctrs-based palettes (@teunbrand, #6117).
32+
* Fixed regression in `guide_bins(reverse = TRUE)` (@teunbrand, #6183).
33+
* New function family for setting parts of a theme. For example, you can now use
34+
`theme_sub_axis(line, text, ticks, ticks.length, line)` as a substitute for
35+
`theme(axis.line, axis.text, axis.ticks, axis.ticks.length, axis.line)`. This
36+
should allow slightly terser and more organised theme declarations
37+
(@teunbrand, #5301).
38+
* `scale_{x/y}_discrete(continuous.limits)` is a new argument to control the
39+
display range of discrete scales (@teunbrand, #4174, #6259).
340
* `geom_ribbon()` now appropriately warns about, and removes, missing values
441
(@teunbrand, #6243).
542
* `guide_*()` can now accept two inside legend theme elements:
@@ -44,6 +81,13 @@
4481
(@teunbrand, #4320)
4582
* `geom_boxplot()` gains additional arguments to style the colour, linetype and
4683
linewidths of the box, whiskers, median line and staples (@teunbrand, #5126)
84+
* `geom_violin()` gains additional arguments to style the colour, linetype and
85+
linewidths of the quantiles, which replace the now-deprecated `draw_quantiles`
86+
argument (#5912).
87+
* (breaking) `geom_violin(quantiles)` now has actual quantiles based on
88+
the data, rather than inferred quantiles based on the computed density. The
89+
`quantiles` parameter that replaces `draw_quantiles` now belongs to
90+
`stat_ydensity()` instead of `geom_violin()` (@teunbrand, #4120).
4791
* (internal) Using `after_scale()` in the `Geom*$default_aes()` field is now
4892
evaluated in the context of data (@teunbrand, #6135)
4993
* Fixed bug where binned scales wouldn't simultaneously accept transformations
@@ -232,7 +276,7 @@
232276
* The ellipsis argument is now checked in `fortify()`, `get_alt_text()`,
233277
`labs()` and several guides (@teunbrand, #3196).
234278
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
235-
* Added `keep.zeroes` argument to `stat_bin()` (@teunbrand, #3449)
279+
* Reintroduced `drop` argument to `stat_bin()` (@teunbrand, #3449)
236280
* (internal) removed barriers for using 2D structures as aesthetics
237281
(@teunbrand, #4189).
238282
* `coord_sf()` no longer errors when dealing with empty graticules (@teunbrand, #6052)
@@ -245,6 +289,25 @@
245289
* `geom_abline()` clips to the panel range in the vertical direction too
246290
(@teunbrand, #6086).
247291
* Added `panel.widths` and `panel.heights` to `theme()` (#5338, @teunbrand).
292+
* Standardised the calculation of `width`, which are now implemented as
293+
aesthetics (@teunbrand, #2800).
294+
* Stricter check on `register_theme_elements(element_tree)` (@teunbrand, #6162)
295+
* Added `weight` aesthetic for `stat_ellipse()` (@teunbrand, #5272)
296+
* Fixed a bug where the `guide_custom(order)` wasn't working (@teunbrand, #6195)
297+
* All binning stats now use the `boundary`/`center` parametrisation rather
298+
than `origin`, following in `stat_bin()`'s footsteps (@teunbrand).
299+
* `stat_summary_2d()` and `stat_bin_2d()` now deal with zero-range data
300+
more elegantly (@teunbrand, #6207).
301+
* Munching in `coord_polar()` and `coord_radial()` now adds more detail,
302+
particularly for data-points with a low radius near the center
303+
(@teunbrand, #5023).
304+
* All scales now expose the `aesthetics` parameter (@teunbrand, #5841)
305+
* Staged expressions are handled more gracefully if legends cannot resolve them
306+
(@teunbrand, #6264).
307+
* New `theme(legend.key.justification)` to control the alignment of legend keys
308+
(@teunbrand, #3669).
309+
* Added `scale_{x/y}_time(date_breaks, date_minor_breaks, date_labels)`
310+
(@teunbrand, #4335).
248311

249312
# ggplot2 3.5.1
250313

R/aes.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ NULL
3838
#'
3939
#' [Delayed evaluation][aes_eval] for working with computed variables.
4040
#'
41+
#' @note
42+
#' Using `I()` to create objects of class 'AsIs' causes scales to ignore the
43+
#' variable and assumes the wrapped variable is direct input for the grid
44+
#' package. Please be aware that variables are sometimes combined, like in
45+
#' some stats or position adjustments, that may yield unexpected results with
46+
#' 'AsIs' variables.
47+
#'
4148
#' @family aesthetics documentation
4249
#' @return A list with class `uneval`. Components of the list are either
4350
#' quosures or constants.

R/axis-secondary.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
329329
scale$train(range)
330330
scale
331331
},
332-
make_title = function(title) {
333-
title
332+
make_title = function(...) {
333+
ScaleContinuous$make_title(...)
334334
}
335335
)

R/bin.R

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,12 @@ bin_breaks <- function(breaks, closed = c("right", "left")) {
5454

5555
bin_breaks_width <- function(x_range, width = NULL, center = NULL,
5656
boundary = NULL, closed = c("right", "left")) {
57-
check_length(x_range, 2L)
5857

59-
# binwidth seems to be the argument name supplied to width. (stat-bin and stat-bindot)
60-
check_number_decimal(width, min = 0, allow_infinite = FALSE, arg = "binwidth")
61-
62-
if (!is.null(boundary) && !is.null(center)) {
63-
cli::cli_abort("Only one of {.arg boundary} and {.arg center} may be specified.")
64-
} else if (is.null(boundary)) {
58+
if (is.null(boundary)) {
6559
if (is.null(center)) {
6660
# If neither edge nor center given, compute both using tile layer's
6761
# algorithm. This puts min and max of data in outer half of their bins.
6862
boundary <- width / 2
69-
7063
} else {
7164
# If center given but not boundary, compute boundary.
7265
boundary <- center - width / 2
@@ -75,9 +68,6 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
7568

7669
# Find the left side of left-most bin: inputs could be Dates or POSIXct, so
7770
# coerce to numeric first.
78-
x_range <- as.numeric(x_range)
79-
width <- as.numeric(width)
80-
boundary <- as.numeric(boundary)
8171
shift <- floor((x_range[1] - boundary) / width)
8272
origin <- boundary + shift * width
8373

@@ -104,9 +94,7 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
10494

10595
bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
10696
boundary = NULL, closed = c("right", "left")) {
107-
check_length(x_range, 2L)
10897

109-
check_number_whole(bins, min = 1)
11098
if (zero_range(x_range)) {
11199
# 0.1 is the same width as the expansion `default_expansion()` gives for 0-width data
112100
width <- 0.1
@@ -128,6 +116,56 @@ bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
128116

129117
# Compute bins ------------------------------------------------------------
130118

119+
compute_bins <- function(x, scale = NULL, breaks = NULL, binwidth = NULL, bins = NULL,
120+
center = NULL, boundary = NULL,
121+
closed = c("right", "left")) {
122+
123+
range <- if (is.scale(scale)) scale$dimension() else range(x)
124+
check_length(range, 2L)
125+
126+
if (!is.null(breaks)) {
127+
breaks <- allow_lambda(breaks)
128+
if (is.function(breaks)) {
129+
breaks <- breaks(x)
130+
}
131+
if (is.scale(scale) && !scale$is_discrete()) {
132+
breaks <- scale$transform(breaks)
133+
}
134+
check_numeric(breaks)
135+
bins <- bin_breaks(breaks, closed)
136+
return(bins)
137+
}
138+
139+
check_number_decimal(boundary, allow_infinite = FALSE, allow_null = TRUE)
140+
check_number_decimal(center, allow_infinite = FALSE, allow_null = TRUE)
141+
if (!is.null(boundary) && !is.null(center)) {
142+
cli::cli_abort("Only one of {.arg boundary} and {.arg center} may be specified.")
143+
}
144+
145+
if (!is.null(binwidth)) {
146+
binwidth <- allow_lambda(binwidth)
147+
if (is.function(binwidth)) {
148+
binwidth <- binwidth(x)
149+
}
150+
check_number_decimal(binwidth, min = 0, allow_infinite = FALSE)
151+
bins <- bin_breaks_width(
152+
range, binwidth,
153+
center = center, boundary = boundary, closed = closed
154+
)
155+
return(bins)
156+
}
157+
158+
bins <- allow_lambda(bins)
159+
if (is.function(bins)) {
160+
bins <- bins(x)
161+
}
162+
check_number_whole(bins, min = 1, allow_infinite = FALSE)
163+
bin_breaks_bins(
164+
range, bins,
165+
center = center, boundary = boundary, closed = closed
166+
)
167+
}
168+
131169
bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
132170
check_object(bins, is_bins, "a {.cls ggplot2_bins} object")
133171

@@ -141,8 +179,7 @@ bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
141179
weight[is.na(weight)] <- 0
142180
}
143181

144-
bin_idx <- cut(x, bins$fuzzy, right = bins$right_closed,
145-
include.lowest = TRUE)
182+
bin_idx <- bin_cut(x, bins)
146183
bin_count <- as.numeric(tapply(weight, bin_idx, sum, na.rm = TRUE))
147184
bin_count[is.na(bin_count)] <- 0
148185

@@ -170,6 +207,10 @@ bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
170207
bin_out(bin_count, bin_x, bin_widths)
171208
}
172209

210+
bin_cut <- function(x, bins) {
211+
cut(x, bins$fuzzy, right = bins$right_closed, include.lowest = TRUE)
212+
}
213+
173214
bin_out <- function(count = integer(0), x = numeric(0), width = numeric(0),
174215
xmin = x - width / 2, xmax = x + width / 2) {
175216
density <- count / width / sum(abs(count))
@@ -186,3 +227,41 @@ bin_out <- function(count = integer(0), x = numeric(0), width = numeric(0),
186227
.size = length(count)
187228
)
188229
}
230+
231+
bin_loc <- function(x, id) {
232+
left <- x[-length(x)]
233+
right <- x[-1]
234+
235+
list(
236+
left = left[id],
237+
right = right[id],
238+
mid = ((left + right) / 2)[id],
239+
length = diff(x)[id]
240+
)
241+
}
242+
243+
fix_bin_params = function(params, fun, version) {
244+
245+
if (!is.null(params$origin)) {
246+
args <- paste0(fun, c("(origin)", "(boundary)"))
247+
deprecate_warn0(version, args[1], args[2])
248+
params$boudnary <- params$origin
249+
params$origin <- NULL
250+
}
251+
252+
if (!is.null(params$right)) {
253+
args <- paste0(fun, c("(right)", "(closed)"))
254+
deprecate_warn0(version, args[1], args[2])
255+
params$closed <- if (isTRUE(params$right)) "right" else "left"
256+
params$right <- NULL
257+
}
258+
259+
if (is.null(params$breaks %||% params$binwidth %||% params$bins)) {
260+
cli::cli_inform(
261+
"{.fn {fun}} using {.code bins = 30}. Pick better value {.arg binwidth}."
262+
)
263+
params$bins <- 30
264+
}
265+
266+
params
267+
}

R/coord-polar.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ CoordPolar <- ggproto("CoordPolar", Coord,
8484

8585
is_free = function() TRUE,
8686

87-
distance = function(self, x, y, details) {
87+
distance = function(self, x, y, details, boost = 0.75) {
8888
arc <- self$start + c(0, 2 * pi)
8989
dir <- self$direction
9090
if (self$theta == "x") {
@@ -94,8 +94,8 @@ CoordPolar <- ggproto("CoordPolar", Coord,
9494
r <- rescale(x, from = details$r.range)
9595
theta <- theta_rescale_no_clip(y, details$theta.range, arc, dir)
9696
}
97-
98-
dist_polar(r, theta)
97+
# The ^boost boosts detailed munching when r is small
98+
dist_polar(r^boost, theta)
9999
},
100100

101101
backtransform_range = function(self, panel_params) {

0 commit comments

Comments
 (0)