Skip to content

Commit 3bc70b5

Browse files
authored
Merge branch 'main' into empty_coord_radial_axes
2 parents de2648b + 12d1c98 commit 3bc70b5

File tree

203 files changed

+2899
-1341
lines changed

Some content is hidden

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

203 files changed

+2899
-1341
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: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
* `coord_radial()` now displays no axis instead of throwing an error when
44
a scale has no breaks (@teunbrand, #6271).
5+
* The `fatten` argument has been deprecated in `geom_boxplot()`,
6+
`geom_crossbar()` and `geom_pointrange()` (@teunbrand, #4881).
7+
* Axis labels are now preserved better when using `coord_sf(expand = TRUE)` and
8+
graticule lines are straight but do not meet the edge (@teunbrand, #2985).
9+
* Attempt to boost detail in `coord_polar()` and `coord_radial()` near the
10+
center (@teunbrand, #5023)
11+
* Scale names, guide titles and aesthetic labels can now accept functions
12+
(@teunbrand, #4313)
13+
* Binned scales with zero-width data expand the default limits by 0.1
14+
(@teunbrand, #5066)
15+
* New default `geom_qq_line(geom = "abline")` for better clipping in the
16+
vertical direction. In addition, `slope` and `intercept` are new computed
17+
variables in `stat_qq_line()` (@teunbrand, #6087).
18+
* Position adjustments can now have auxiliary aesthetics (@teunbrand).
19+
* `position_nudge()` gains `nudge_x` and `nudge_y` aesthetics (#3026, #5445).
20+
* `position_dodge()` gains `order` aesthetic (#3022, #3345)
21+
* More stability for vctrs-based palettes (@teunbrand, #6117).
22+
* Fixed regression in `guide_bins(reverse = TRUE)` (@teunbrand, #6183).
23+
* New function family for setting parts of a theme. For example, you can now use
24+
`theme_sub_axis(line, text, ticks, ticks.length, line)` as a substitute for
25+
`theme(axis.line, axis.text, axis.ticks, axis.ticks.length, axis.line)`. This
26+
should allow slightly terser and more organised theme declarations
27+
(@teunbrand, #5301).
28+
* `scale_{x/y}_discrete(continuous.limits)` is a new argument to control the
29+
display range of discrete scales (@teunbrand, #4174, #6259).
530
* `geom_ribbon()` now appropriately warns about, and removes, missing values
631
(@teunbrand, #6243).
732
* `guide_*()` can now accept two inside legend theme elements:
@@ -46,6 +71,13 @@
4671
(@teunbrand, #4320)
4772
* `geom_boxplot()` gains additional arguments to style the colour, linetype and
4873
linewidths of the box, whiskers, median line and staples (@teunbrand, #5126)
74+
* `geom_violin()` gains additional arguments to style the colour, linetype and
75+
linewidths of the quantiles, which replace the now-deprecated `draw_quantiles`
76+
argument (#5912).
77+
* (breaking) `geom_violin(quantiles)` now has actual quantiles based on
78+
the data, rather than inferred quantiles based on the computed density. The
79+
`quantiles` parameter that replaces `draw_quantiles` now belongs to
80+
`stat_ydensity()` instead of `geom_violin()` (@teunbrand, #4120).
4981
* (internal) Using `after_scale()` in the `Geom*$default_aes()` field is now
5082
evaluated in the context of data (@teunbrand, #6135)
5183
* Fixed bug where binned scales wouldn't simultaneously accept transformations
@@ -234,7 +266,7 @@
234266
* The ellipsis argument is now checked in `fortify()`, `get_alt_text()`,
235267
`labs()` and several guides (@teunbrand, #3196).
236268
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
237-
* Added `keep.zeroes` argument to `stat_bin()` (@teunbrand, #3449)
269+
* Reintroduced `drop` argument to `stat_bin()` (@teunbrand, #3449)
238270
* (internal) removed barriers for using 2D structures as aesthetics
239271
(@teunbrand, #4189).
240272
* `coord_sf()` no longer errors when dealing with empty graticules (@teunbrand, #6052)
@@ -247,6 +279,19 @@
247279
* `geom_abline()` clips to the panel range in the vertical direction too
248280
(@teunbrand, #6086).
249281
* Added `panel.widths` and `panel.heights` to `theme()` (#5338, @teunbrand).
282+
* Standardised the calculation of `width`, which are now implemented as
283+
aesthetics (@teunbrand, #2800).
284+
* Stricter check on `register_theme_elements(element_tree)` (@teunbrand, #6162)
285+
* Added `weight` aesthetic for `stat_ellipse()` (@teunbrand, #5272)
286+
* Fixed a bug where the `guide_custom(order)` wasn't working (@teunbrand, #6195)
287+
* All binning stats now use the `boundary`/`center` parametrisation rather
288+
than `origin`, following in `stat_bin()`'s footsteps (@teunbrand).
289+
* `stat_summary_2d()` and `stat_bin_2d()` now deal with zero-range data
290+
more elegantly (@teunbrand, #6207).
291+
* Munching in `coord_polar()` and `coord_radial()` now adds more detail,
292+
particularly for data-points with a low radius near the center
293+
(@teunbrand, #5023).
294+
* All scales now expose the `aesthetics` parameter (@teunbrand, #5841)
250295

251296
# ggplot2 3.5.1
252297

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) {

R/coord-radial.R

Lines changed: 6 additions & 6 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:
@@ -120,7 +120,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
120120

121121
is_free = function() TRUE,
122122

123-
distance = function(self, x, y, details) {
123+
distance = function(self, x, y, details, boost = 0.75) {
124124
arc <- details$arc %||% c(0, 2 * pi)
125125
if (self$theta == "x") {
126126
r <- rescale(y, from = details$r.range, to = self$inner_radius / 0.4)
@@ -129,8 +129,8 @@ CoordRadial <- ggproto("CoordRadial", Coord,
129129
r <- rescale(x, from = details$r.range, to = self$inner_radius / 0.4)
130130
theta <- theta_rescale_no_clip(y, details$theta.range, arc)
131131
}
132-
133-
dist_polar(r, theta)
132+
# The ^boost boosts detailed munching when r is small
133+
dist_polar(r^boost, theta)
134134
},
135135

136136
backtransform_range = function(self, panel_params) {
@@ -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)
@@ -611,7 +611,7 @@ theta_grid <- function(theta, element, inner_radius = c(0, 0.4),
611611
)
612612
}
613613

614-
check_polar_guide <- function(drop_list, guides, type = "theta") {
614+
validate_polar_guide <- function(drop_list, guides, type = "theta") {
615615
guide <- guides$get_guide(type)
616616
primary <- gsub("\\.sec$", "", type)
617617
if (inherits(guide, "GuideNone") || primary %in% guide$available_aes) {

R/coord-sf.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,14 @@ view_scales_from_graticule <- function(graticule, scale, aesthetic,
721721
accept_start <- graticule[[orth_start]] < thres
722722
accept_end <- graticule[[orth_end]] < thres
723723
}
724+
if (!any(accept_start | accept_end)) {
725+
eps <- sqrt(.Machine$double.xmin)
726+
subtract <- switch(position, top = , bottom = 90, 0)
727+
straight <-
728+
abs(graticule$angle_start - subtract) < eps &
729+
abs(graticule$angle_end - subtract) < eps
730+
accept_start <- straight
731+
}
724732

725733
# Parsing the information of the `label_axes` argument:
726734
# should we label the meridians ("E") or parallels ("N")?

0 commit comments

Comments
 (0)