Skip to content

Commit 4cda87d

Browse files
committed
resolve merge conflict
Merge branch 'main' into polar_tweaks # Conflicts: # tests/testthat/_snaps/geom-violin/coord-polar.svg
2 parents 5e8b749 + e30642b commit 4cda87d

File tree

146 files changed

+2123
-877
lines changed

Some content is hidden

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

146 files changed

+2123
-877
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: 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: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# ggplot2 (development version)
22

3+
* Binned scales with zero-width data expand the default limits by 0.1
4+
(@teunbrand, #5066)
5+
* New default `geom_qq_line(geom = "abline")` for better clipping in the
6+
vertical direction. In addition, `slope` and `intercept` are new computed
7+
variables in `stat_qq_line()` (@teunbrand, #6087).
8+
* Position adjustments can now have auxiliary aesthetics (@teunbrand).
9+
* `position_nudge()` gains `nudge_x` and `nudge_y` aesthetics (#3026, #5445).
10+
* `position_dodge()` gains `order` aesthetic (#3022, #3345)
11+
* More stability for vctrs-based palettes (@teunbrand, #6117).
12+
* Fixed regression in `guide_bins(reverse = TRUE)` (@teunbrand, #6183).
13+
* New function family for setting parts of a theme. For example, you can now use
14+
`theme_sub_axis(line, text, ticks, ticks.length, line)` as a substitute for
15+
`theme(axis.line, axis.text, axis.ticks, axis.ticks.length, axis.line)`. This
16+
should allow slightly terser and more organised theme declarations
17+
(@teunbrand, #5301).
18+
* `scale_{x/y}_discrete(continuous.limits)` is a new argument to control the
19+
display range of discrete scales (@teunbrand, #4174, #6259).
20+
* `geom_ribbon()` now appropriately warns about, and removes, missing values
21+
(@teunbrand, #6243).
322
* `guide_*()` can now accept two inside legend theme elements:
423
`legend.position.inside` and `legend.justification.inside`, allowing inside
524
legends to be placed at different positions. Only inside legends with the same
@@ -42,6 +61,13 @@
4261
(@teunbrand, #4320)
4362
* `geom_boxplot()` gains additional arguments to style the colour, linetype and
4463
linewidths of the box, whiskers, median line and staples (@teunbrand, #5126)
64+
* `geom_violin()` gains additional arguments to style the colour, linetype and
65+
linewidths of the quantiles, which replace the now-deprecated `draw_quantiles`
66+
argument (#5912).
67+
* (breaking) `geom_violin(quantiles)` now has actual quantiles based on
68+
the data, rather than inferred quantiles based on the computed density. The
69+
`quantiles` parameter that replaces `draw_quantiles` now belongs to
70+
`stat_ydensity()` instead of `geom_violin()` (@teunbrand, #4120).
4571
* (internal) Using `after_scale()` in the `Geom*$default_aes()` field is now
4672
evaluated in the context of data (@teunbrand, #6135)
4773
* Fixed bug where binned scales wouldn't simultaneously accept transformations
@@ -230,7 +256,7 @@
230256
* The ellipsis argument is now checked in `fortify()`, `get_alt_text()`,
231257
`labs()` and several guides (@teunbrand, #3196).
232258
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
233-
* Added `keep.zeroes` argument to `stat_bin()` (@teunbrand, #3449)
259+
* Reintroduced `drop` argument to `stat_bin()` (@teunbrand, #3449)
234260
* (internal) removed barriers for using 2D structures as aesthetics
235261
(@teunbrand, #4189).
236262
* `coord_sf()` no longer errors when dealing with empty graticules (@teunbrand, #6052)
@@ -243,6 +269,15 @@
243269
* `geom_abline()` clips to the panel range in the vertical direction too
244270
(@teunbrand, #6086).
245271
* Added `panel.widths` and `panel.heights` to `theme()` (#5338, @teunbrand).
272+
* Standardised the calculation of `width`, which are now implemented as
273+
aesthetics (@teunbrand, #2800).
274+
* Stricter check on `register_theme_elements(element_tree)` (@teunbrand, #6162)
275+
* Added `weight` aesthetic for `stat_ellipse()` (@teunbrand, #5272)
276+
* Fixed a bug where the `guide_custom(order)` wasn't working (@teunbrand, #6195)
277+
* All binning stats now use the `boundary`/`center` parametrisation rather
278+
than `origin`, following in `stat_bin()`'s footsteps (@teunbrand).
279+
* `stat_summary_2d()` and `stat_bin_2d()` now deal with zero-range data
280+
more elegantly (@teunbrand, #6207).
246281

247282
# ggplot2 3.5.1
248283

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/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-radial.R

Lines changed: 5 additions & 5 deletions
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:
@@ -27,10 +27,10 @@
2727
#' @param r_axis_inside,rotate_angle `r lifecycle::badge("deprecated")`
2828
#'
2929
#' @note
30-
#' In `coord_radial()`, position guides are can be defined by using
30+
#' In `coord_radial()`, position guides can be defined by using
3131
#' `guides(r = ..., theta = ..., r.sec = ..., theta.sec = ...)`. Note that
3232
#' these guides require `r` and `theta` as available aesthetics. The classic
33-
#' `guide_axis()` can be used for the `r` positions and `guide_axis_theta()` can
33+
#' [guide_axis()] can be used for the `r` positions and [guide_axis_theta()] can
3434
#' be used for the `theta` positions. Using the `theta.sec` position is only
3535
#' sensible when `inner.radius > 0`.
3636
#'
@@ -191,7 +191,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
191191
# Validate appropriateness of guides
192192
drop_guides <- character(0)
193193
for (type in aesthetics) {
194-
drop_guides <- check_polar_guide(drop_guides, guides, type)
194+
drop_guides <- validate_polar_guide(drop_guides, guides, type)
195195
}
196196

197197
guide_params <- guides$get_params(aesthetics)
@@ -603,7 +603,7 @@ theta_grid <- function(theta, element, inner_radius = c(0, 0.4),
603603
)
604604
}
605605

606-
check_polar_guide <- function(drop_list, guides, type = "theta") {
606+
validate_polar_guide <- function(drop_list, guides, type = "theta") {
607607
guide <- guides$get_guide(type)
608608
primary <- gsub("\\.sec$", "", type)
609609
if (inherits(guide, "GuideNone") || primary %in% guide$available_aes) {

R/facet-.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ df.grid <- function(a, b) {
443443
# facetting variables.
444444

445445
as_facets_list <- function(x) {
446-
x <- validate_facets(x)
446+
check_vars(x)
447447
if (is_quosures(x)) {
448448
x <- quos_auto_name(x)
449449
return(list(x))
@@ -487,7 +487,7 @@ as_facets_list <- function(x) {
487487
x
488488
}
489489

490-
validate_facets <- function(x) {
490+
check_vars <- function(x) {
491491
if (is.mapping(x)) {
492492
cli::cli_abort("Please use {.fn vars} to supply facet variables.")
493493
}
@@ -499,7 +499,7 @@ validate_facets <- function(x) {
499499
"i" = "Did you use {.code %>%} or {.code |>} instead of {.code +}?"
500500
))
501501
}
502-
x
502+
invisible()
503503
}
504504

505505
# Flatten a list of quosures objects to a quosures object, and compact it

R/facet-grid-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ facet_grid <- function(rows = NULL, cols = NULL, scales = "fixed",
177177
facets_list <- grid_as_facets_list(rows, cols)
178178

179179
# Check for deprecated labellers
180-
labeller <- check_labeller(labeller)
180+
labeller <- fix_labeller(labeller)
181181

182182
ggproto(NULL, FacetGrid,
183183
shrink = shrink,

R/facet-wrap.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed",
174174
)
175175

176176
# Check for deprecated labellers
177-
labeller <- check_labeller(labeller)
177+
labeller <- fix_labeller(labeller)
178178

179179
# Flatten all facets dimensions into a single one
180180
facets <- compact_facets(facets)

0 commit comments

Comments
 (0)