Skip to content

Commit 07c2f28

Browse files
authored
Merge branch 'main' into geom_bar_stat_sum
2 parents 376b04f + b9d1c79 commit 07c2f28

File tree

206 files changed

+3160
-1386
lines changed

Some content is hidden

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

206 files changed

+3160
-1386
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: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

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

251300
# ggplot2 3.5.1
252301

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)