Skip to content

Commit e718db1

Browse files
committed
Merge branch 'main' into theme_geom_defaults
2 parents e728d19 + c108758 commit e718db1

File tree

109 files changed

+794
-401
lines changed

Some content is hidden

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

109 files changed

+794
-401
lines changed

NEWS.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
* The `element_geom()` function can be used to populate that argument.
77
* The `from_theme()` function allows access to the theme default fields from
88
inside the `aes()` function.
9+
* `facet_wrap()` can have `space = "free_x"` with 1-row layouts and
10+
`space = "free_y"` with 1-column layouts (@teunbrand)
11+
* Secondary axes respect `n.breaks` setting in continuous scales (@teunbrand, #4483).
12+
* Layers can have names (@teunbrand, #4066).
13+
* (internal) improvements to `pal_qualitative()` (@teunbrand, #5013)
14+
* `coord_radial(clip = "on")` clips to the panel area when the graphics device
15+
supports clipping paths (@teunbrand, #5952).
16+
* (internal) Panel clipping responsibility moved from Facet class to Coord
17+
class through new `Coord$draw_panel()` method.
18+
* `theme(strip.clip)` now defaults to `"on"` and is independent of Coord
19+
clipping (@teunbrand, 5952).
20+
* (internal) rearranged the code of `Facet$draw_paensl()` method (@teunbrand).
21+
* Axis labels are now justified across facet panels (@teunbrand, #5820)
922
* Fixed bug in `stat_function()` so x-axis title now produced automatically
1023
when no data added. (@phispu, #5647).
1124
* geom_sf now accepts shape names (@sierrajohnson, #5808)
@@ -143,6 +156,8 @@
143156
(@teunbrand, #5938, #4327).
144157
* Fixed bug where empty discrete scales weren't recognised as such
145158
(@teunbrand, #5945).
159+
* (internal) The summary function of `stat_summary()` and `stat_summary_bin()`
160+
is setup once in total instead of once per group (@teunbrand, #5971)
146161

147162
# ggplot2 3.5.1
148163

R/annotation-logticks.R

Lines changed: 3 additions & 3 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
@@ -243,7 +243,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
243243
# - start: on the other axis, start position of the line (usually 0)
244244
# - end: on the other axis, end position of the line (for example, .1, .2, or .3)
245245
calc_logticks <- function(base = 10, ticks_per_base = base - 1,
246-
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) {
247247

248248
# Number of blocks of tick marks
249249
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ Coord <- ggproto("Coord",
208208
# used as a fudge for CoordFlip and CoordPolar
209209
modify_scales = function(scales_x, scales_y) {
210210
invisible()
211+
},
212+
213+
draw_panel = function(self, panel, params, theme) {
214+
fg <- self$render_fg(params, theme)
215+
bg <- self$render_bg(params, theme)
216+
if (isTRUE(theme$panel.ontop)) {
217+
panel <- list2(!!!panel, bg, fg)
218+
} else {
219+
panel <- list2(bg, !!!panel, fg)
220+
}
221+
gTree(
222+
children = inject(gList(!!!panel)),
223+
vp = viewport(clip = self$clip)
224+
)
211225
}
212226
)
213227

R/coord-polar.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ CoordPolar <- ggproto("CoordPolar", Coord,
137137
ret[[n]]$sec.labels <- out$sec.labels
138138
}
139139

140-
details = list(
140+
details <- list(
141141
x.range = ret$x$range, y.range = ret$y$range,
142142
x.major = ret$x$major, y.major = ret$y$major,
143143
x.minor = ret$x$minor, y.minor = ret$y$minor,

R/coord-radial.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,27 @@ CoordRadial <- ggproto("CoordRadial", Coord,
409409
)
410410
},
411411

412+
413+
draw_panel = function(self, panel, params, theme) {
414+
clip_support <- check_device("clippingPaths", "test", maybe = TRUE)
415+
if (self$clip == "on" && !isFALSE(clip_support)) {
416+
clip_path <- data_frame0(
417+
x = c(Inf, Inf, -Inf, -Inf),
418+
y = c(Inf, -Inf, -Inf, Inf)
419+
)
420+
clip_path <- coord_munch(self, clip_path, params, is_closed = TRUE)
421+
clip_path <- polygonGrob(clip_path$x, clip_path$y)
422+
# Note that clipping path is applied to panel without coord
423+
# foreground/background (added in parent method).
424+
# These may contain decorations that needn't be clipped
425+
panel <- list(gTree(
426+
children = inject(gList(!!!panel)),
427+
vp = viewport(clip = clip_path)
428+
))
429+
}
430+
ggproto_parent(Coord, self)$draw_panel(panel, params, theme)
431+
},
432+
412433
labels = function(self, labels, panel_params) {
413434
# `Layout$resolve_label()` doesn't know to look for theta/r/r.sec guides,
414435
# so we'll handle title propagation here.

R/coord-sf.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ sf_rescale01 <- function(x, x_range, y_range) {
416416

417417
# different limits methods
418418
calc_limits_bbox <- function(method, xlim, ylim, crs, default_crs) {
419-
if (any(!is.finite(c(xlim, ylim))) && method != "geometry_bbox") {
419+
if (!all(is.finite(c(xlim, ylim))) && method != "geometry_bbox") {
420420
cli::cli_abort(c(
421421
"Scale limits cannot be mapped onto spatial coordinates in {.fn coord_sf}.",
422422
"i" = "Consider setting {.code lims_method = \"geometry_bbox\"} or {.code default_crs = NULL}."
@@ -585,7 +585,7 @@ coord_sf <- function(xlim = NULL, ylim = NULL, expand = TRUE,
585585
}
586586

587587
parse_axes_labeling <- function(x) {
588-
labs = unlist(strsplit(x, ""))
588+
labs <- unlist(strsplit(x, ""))
589589
list(top = labs[1], right = labs[2], bottom = labs[3], left = labs[4])
590590
}
591591

R/facet-.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ Facet <- ggproto("Facet", NULL,
153153

154154
table <- self$init_gtable(
155155
panels, layout, theme, ranges, params,
156-
aspect_ratio = aspect_ratio %||% coord$aspect(ranges[[1]]),
157-
clip = coord$clip
156+
aspect_ratio = aspect_ratio %||% coord$aspect(ranges[[1]])
158157
)
159158

160159
table <- self$attach_axes(table, layout, ranges, coord, theme, params)
@@ -198,7 +197,7 @@ Facet <- ggproto("Facet", NULL,
198197
data
199198
},
200199
init_gtable = function(panels, layout, theme, ranges, params,
201-
aspect_ratio = NULL, clip = "on") {
200+
aspect_ratio = NULL) {
202201

203202
# Initialise matrix of panels
204203
dim <- c(max(layout$ROW), max(layout$COL))
@@ -228,7 +227,7 @@ Facet <- ggproto("Facet", NULL,
228227
"layout", table,
229228
widths = widths, heights = heights,
230229
respect = !is.null(aspect_ratio),
231-
clip = clip, z = matrix(1, dim[1], dim[2])
230+
clip = "off", z = matrix(1, dim[1], dim[2])
232231
)
233232

234233
# Set panel names
@@ -678,7 +677,7 @@ find_panel <- function(table) {
678677
}
679678
#' @rdname find_panel
680679
#' @export
681-
panel_cols = function(table) {
680+
panel_cols <- function(table) {
682681
panels <- table$layout[grepl("^panel", table$layout$name), , drop = FALSE]
683682
unique0(panels[, c('l', 'r')])
684683
}

0 commit comments

Comments
 (0)