Skip to content

Commit 832a0ea

Browse files
authored
Merge branch 'main' into type-date_breaks
2 parents 2cef6bb + 2bd8cd5 commit 832a0ea

File tree

239 files changed

+7901
-8323
lines changed

Some content is hidden

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

239 files changed

+7901
-8323
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ Imports:
3939
isoband,
4040
lifecycle (> 1.0.1),
4141
MASS,
42-
mgcv,
4342
rlang (>= 1.1.0),
4443
scales (>= 1.3.0),
4544
stats,
46-
tibble,
4745
vctrs (>= 0.6.0),
4846
withr (>= 2.5.0)
4947
Suggests:
@@ -55,6 +53,7 @@ Suggests:
5553
knitr,
5654
mapproj,
5755
maps,
56+
mgcv,
5857
multcomp,
5958
munsell,
6059
nlme,
@@ -67,6 +66,7 @@ Suggests:
6766
sf (>= 0.7-3),
6867
svglite (>= 2.1.2),
6968
testthat (>= 3.1.5),
69+
tibble,
7070
vdiffr (>= 1.0.6),
7171
xml2
7272
Enhances:

NAMESPACE

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ export(draw_key_vpath)
344344
export(dup_axis)
345345
export(el_def)
346346
export(element_blank)
347+
export(element_geom)
347348
export(element_grob)
348349
export(element_line)
349350
export(element_rect)
@@ -367,6 +368,7 @@ export(find_panel)
367368
export(flip_data)
368369
export(flipped_names)
369370
export(fortify)
371+
export(from_theme)
370372
export(geom_abline)
371373
export(geom_area)
372374
export(geom_bar)
@@ -422,6 +424,7 @@ export(geom_violin)
422424
export(geom_vline)
423425
export(get_alt_text)
424426
export(get_element_tree)
427+
export(get_geom_defaults)
425428
export(get_guide_data)
426429
export(get_last_plot)
427430
export(get_layer_data)
@@ -513,6 +516,8 @@ export(remove_missing)
513516
export(render_axes)
514517
export(render_strips)
515518
export(replace_theme)
519+
export(reset_geom_defaults)
520+
export(reset_stat_defaults)
516521
export(reset_theme_settings)
517522
export(resolution)
518523
export(scale_alpha)
@@ -733,7 +738,6 @@ importFrom(grid,unit)
733738
importFrom(lifecycle,deprecated)
734739
importFrom(scales,alpha)
735740
importFrom(stats,setNames)
736-
importFrom(tibble,tibble)
737741
importFrom(utils,.DollarNames)
738742
importFrom(utils,head)
739743
importFrom(utils,tail)

NEWS.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@
22

33
* Date(time) scales now throw appropriate errors when `date_breaks`,
44
`date_minor_breaks` or `date_labels` are not strings (@RodDalBen, #5880)
5+
* The `summary()` method for ggplots is now more terse about facets
6+
(@teunbrand, #5989).
7+
* `guide_bins()`, `guide_colourbar()` and `guide_coloursteps()` gain an `angle`
8+
argument to overrule theme settings, similar to `guide_axis(angle)`
9+
(@teunbrand, #4594).
10+
* `coord_*(expand)` can now take a logical vector to control expansion at any
11+
side of the panel (top, right, bottom, left) (@teunbrand, #6020)
12+
* (Breaking) The defaults for all geoms can be set at one in the theme.
13+
(@teunbrand based on pioneering work by @dpseidel, #2239)
14+
* A new `theme(geom)` argument is used to track these defaults.
15+
* The `element_geom()` function can be used to populate that argument.
16+
* The `from_theme()` function allows access to the theme default fields from
17+
inside the `aes()` function.
18+
* Passing empty unmapped aesthetics to layers raises a warning instead of
19+
throwing an error (@teunbrand, #6009).
20+
* Moved {mgcv} from Imports to Suggests (@teunbrand, #5986)
21+
* New `reset_geom_defaults()` and `reset_stat_defaults()` to restore all geom or
22+
stat default aesthetics at once (@teunbrand, #5975).
23+
* `facet_wrap()` can have `space = "free_x"` with 1-row layouts and
24+
`space = "free_y"` with 1-column layouts (@teunbrand)
25+
* Secondary axes respect `n.breaks` setting in continuous scales (@teunbrand, #4483).
26+
* Layers can have names (@teunbrand, #4066).
27+
* (internal) improvements to `pal_qualitative()` (@teunbrand, #5013)
28+
* `coord_radial(clip = "on")` clips to the panel area when the graphics device
29+
supports clipping paths (@teunbrand, #5952).
30+
* (internal) Panel clipping responsibility moved from Facet class to Coord
31+
class through new `Coord$draw_panel()` method.
32+
* `theme(strip.clip)` now defaults to `"on"` and is independent of Coord
33+
clipping (@teunbrand, 5952).
34+
* (internal) rearranged the code of `Facet$draw_panels()` method (@teunbrand).
35+
* Axis labels are now justified across facet panels (@teunbrand, #5820)
36+
* Fixed bug in `stat_function()` so x-axis title now produced automatically
37+
when no data added. (@phispu, #5647).
38+
* geom_sf now accepts shape names (@sierrajohnson, #5808)
39+
* Added `gg` class to `labs()` (@phispu, #5553).
540
* Missing values from discrete palettes are no longer translated
641
(@teunbrand, #5929).
742
* Fixed bug in `facet_grid(margins = TRUE)` when using expresssions
@@ -135,6 +170,16 @@
135170
(@teunbrand, #5938, #4327).
136171
* Fixed bug where empty discrete scales weren't recognised as such
137172
(@teunbrand, #5945).
173+
* (internal) The summary function of `stat_summary()` and `stat_summary_bin()`
174+
is setup once in total instead of once per group (@teunbrand, #5971)
175+
* `facet_grid(space = "free")` can now be combined with `coord_fixed()`
176+
(@teunbrand, #4584).
177+
* `theme_classic()` now has black ticks and text instead of dark gray. In
178+
addition, `theme_classic()`'s axis line end is `"square"` (@teunbrand, #5978).
179+
* {tibble} is now suggested instead of imported (@teunbrand, #5986)
180+
* The ellipsis argument is now checked in `fortify()`, `get_alt_text()`,
181+
`labs()` and several guides (@teunbrand, #3196).
182+
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
138183

139184
# ggplot2 3.5.1
140185

R/aes-evaluation.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@
109109
#' fun.data = ~ round(data.frame(mean = mean(.x), sd = sd(.x)), 2)
110110
#' )
111111
#' ```
112+
#'
113+
#' ## Theme access
114+
#' The `from_theme()` function can be used to acces the [`element_geom()`]
115+
#' fields of the `theme(geom)` argument. Using `aes(colour = from_theme(ink))`
116+
#' and `aes(colour = from_theme(accent))` allows swapping between foreground and
117+
#' accent colours.
118+
#'
112119
#' @rdname aes_eval
113120
#' @name aes_eval
114121
#'
@@ -192,6 +199,13 @@ stat <- function(x) {
192199
after_scale <- function(x) {
193200
x
194201
}
202+
203+
#' @rdname aes_eval
204+
#' @export
205+
from_theme <- function(x) {
206+
x
207+
}
208+
195209
#' @rdname aes_eval
196210
#' @export
197211
stage <- function(start = NULL, after_stat = NULL, after_scale = NULL) {
@@ -221,6 +235,9 @@ is_scaled_aes <- function(aesthetics) {
221235
is_staged_aes <- function(aesthetics) {
222236
vapply(aesthetics, is_staged, logical(1), USE.NAMES = FALSE)
223237
}
238+
is_themed_aes <- function(aesthetics) {
239+
vapply(aesthetics, is_themed, logical(1), USE.NAMES = FALSE)
240+
}
224241
is_calculated <- function(x, warn = FALSE) {
225242
if (is_call(get_expr(x), "after_stat")) {
226243
return(TRUE)
@@ -263,6 +280,9 @@ is_scaled <- function(x) {
263280
is_staged <- function(x) {
264281
is_call(get_expr(x), "stage")
265282
}
283+
is_themed <- function(x) {
284+
is_call(get_expr(x), "from_theme")
285+
}
266286

267287
# Strip dots from expressions
268288
strip_dots <- function(expr, env, strip_pronoun = FALSE) {

R/annotation-logticks.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
165165

166166
names(xticks)[names(xticks) == "value"] <- x_name # Rename to 'x' for coordinates$transform
167167
xticks <- coord$transform(xticks, panel_params)
168-
xticks = xticks[xticks$x <= 1 & xticks$x >= 0,]
168+
xticks <- xticks[xticks$x <= 1 & xticks$x >= 0,]
169169

170170
if (outside)
171171
xticks$end = -xticks$end
@@ -203,7 +203,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
203203

204204
names(yticks)[names(yticks) == "value"] <- y_name # Rename to 'y' for coordinates$transform
205205
yticks <- coord$transform(yticks, panel_params)
206-
yticks = yticks[yticks$y <= 1 & yticks$y >= 0,]
206+
yticks <- yticks[yticks$y <= 1 & yticks$y >= 0,]
207207

208208
if (outside)
209209
yticks$end = -yticks$end
@@ -228,7 +228,12 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
228228
gTree(children = inject(gList(!!!ticks)))
229229
},
230230

231-
default_aes = aes(colour = "black", linewidth = 0.5, linetype = 1, alpha = 1)
231+
default_aes = aes(
232+
colour = from_theme(ink),
233+
linewidth = from_theme(linewidth),
234+
linetype = from_theme(linetype),
235+
alpha = 1
236+
)
232237
)
233238

234239

@@ -238,7 +243,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
238243
# - start: on the other axis, start position of the line (usually 0)
239244
# - end: on the other axis, end position of the line (for example, .1, .2, or .3)
240245
calc_logticks <- function(base = 10, ticks_per_base = base - 1,
241-
minpow = 0, maxpow = minpow + 1, start = 0, shortend = .1, midend = .2, longend = .3) {
246+
minpow = 0, maxpow = minpow + 1, start = 0, shortend = 0.1, midend = 0.2, longend = 0.3) {
242247

243248
# Number of blocks of tick marks
244249
reps <- maxpow - minpow

R/axis-secondary.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
188188
if (scale$is_discrete()) {
189189
self$breaks <- scale$get_breaks()
190190
} else {
191-
self$breaks <- scale$get_transformation()$breaks
191+
breaks <- scale$get_transformation()$breaks
192+
n_breaks <- scale$n.breaks
193+
if (!is.null(n_breaks) && "n" %in% fn_fmls_names(breaks)) {
194+
self$breaks <- function(x) breaks(x, n = n_breaks)
195+
} else {
196+
self$breaks <- breaks
197+
}
192198
}
193199
}
194200
if (is.derived(self$labels)) self$labels <- scale$labels

R/bin.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
165165
}
166166

167167
# Add row for missings
168-
if (any(is.na(bins))) {
168+
if (anyNA(bins)) {
169169
bin_count <- c(bin_count, sum(is.na(bins)))
170170
bin_widths <- c(bin_widths, NA)
171171
bin_x <- c(bin_x, NA)

R/compat-plyr.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ rename <- function(x, replace) {
5454
id_var <- function(x, drop = FALSE) {
5555
if (length(x) == 0) {
5656
id <- integer()
57-
n = 0L
57+
n <- 0L
5858
} else if (!is.null(attr(x, "n")) && !drop) {
5959
return(x)
6060
} else if (is.factor(x) && !drop) {
6161
x <- addNA(x, ifany = TRUE)
6262
id <- as.integer(x)
63-
n <- length(levels(x))
63+
n <- nlevels(x)
6464
} else {
6565
levels <- sort(unique0(x), na.last = TRUE)
6666
id <- match(x, levels)

R/coord-.R

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,11 @@ Coord <- ggproto("Coord",
184184
# Will generally have to return FALSE for coordinate systems that enforce a fixed aspect ratio.
185185
is_free = function() FALSE,
186186

187-
setup_params = function(data) {
187+
setup_params = function(self, data) {
188188
list(
189189
guide_default = guide_axis(),
190-
guide_missing = guide_none()
190+
guide_missing = guide_none(),
191+
expand = parse_coord_expand(self$expand %||% TRUE)
191192
)
192193
},
193194

@@ -208,6 +209,20 @@ Coord <- ggproto("Coord",
208209
# used as a fudge for CoordFlip and CoordPolar
209210
modify_scales = function(scales_x, scales_y) {
210211
invisible()
212+
},
213+
214+
draw_panel = function(self, panel, params, theme) {
215+
fg <- self$render_fg(params, theme)
216+
bg <- self$render_bg(params, theme)
217+
if (isTRUE(theme$panel.ontop)) {
218+
panel <- list2(!!!panel, bg, fg)
219+
} else {
220+
panel <- list2(bg, !!!panel, fg)
221+
}
222+
gTree(
223+
children = inject(gList(!!!panel)),
224+
vp = viewport(clip = self$clip)
225+
)
211226
}
212227
)
213228

@@ -229,6 +244,26 @@ render_axis <- function(panel_params, axis, scale, position, theme) {
229244
}
230245
}
231246

247+
# Elaborates an 'expand' argument for every side (top, right, bottom or left)
248+
parse_coord_expand <- function(expand) {
249+
check_logical(expand)
250+
if (anyNA(expand)) {
251+
cli::cli_abort("{.arg expand} cannot contain missing values.")
252+
}
253+
254+
if (!is_named(expand)) {
255+
return(rep_len(expand, 4))
256+
}
257+
258+
# Match by top/right/bottom/left
259+
out <- rep(TRUE, 4)
260+
i <- match(names(expand), .trbl)
261+
if (sum(!is.na(i)) > 0) {
262+
out[i] <- unname(expand)[!is.na(i)]
263+
}
264+
out
265+
}
266+
232267
# Utility function to check coord limits
233268
check_coord_limits <- function(
234269
limits, arg = caller_arg(limits), call = caller_env()

R/coord-cartesian-.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#' @param expand If `TRUE`, the default, adds a small expansion factor to
1010
#' the limits to ensure that data and axes don't overlap. If `FALSE`,
1111
#' limits are taken exactly from the data or `xlim`/`ylim`.
12+
#' Giving a logical vector will separately control the expansion for the four
13+
#' directions (top, left, bottom and right). The `expand` argument will be
14+
#' recycled to length 4 if necessary. Alternatively, can be a named logical
15+
#' vector to control a single direction, e.g. `expand = c(bottom = FALSE)`.
1216
#' @param default Is this the default coordinate system? If `FALSE` (the default),
1317
#' then replacing this coordinate system with another one creates a message alerting
1418
#' the user that the coordinate system is being replaced. If `TRUE`, that warning
@@ -100,8 +104,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
100104

101105
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
102106
c(
103-
view_scales_from_scale(scale_x, self$limits$x, self$expand),
104-
view_scales_from_scale(scale_y, self$limits$y, self$expand)
107+
view_scales_from_scale(scale_x, self$limits$x, params$expand[c(4, 2)]),
108+
view_scales_from_scale(scale_y, self$limits$y, params$expand[c(3, 1)])
105109
)
106110
},
107111

0 commit comments

Comments
 (0)