Skip to content

Commit 3968c04

Browse files
committed
Merge branch 'main' into convert_linetype_nas
2 parents ec32b80 + 1bfb3c9 commit 3968c04

Some content is hidden

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

83 files changed

+1332
-279
lines changed

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ S3method(c,mapped_discrete)
2020
S3method(drawDetails,zeroGrob)
2121
S3method(element_grob,element_blank)
2222
S3method(element_grob,element_line)
23+
S3method(element_grob,element_point)
24+
S3method(element_grob,element_polygon)
2325
S3method(element_grob,element_rect)
2426
S3method(element_grob,element_text)
2527
S3method(format,ggproto)
@@ -346,6 +348,8 @@ export(element_blank)
346348
export(element_geom)
347349
export(element_grob)
348350
export(element_line)
351+
export(element_point)
352+
export(element_polygon)
349353
export(element_rect)
350354
export(element_render)
351355
export(element_text)

NEWS.md

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

33
* `linetype = NA` is now interpreted to mean 'no line' instead of raising errors
44
(@teunbrand, #6269).
5+
* New parameters for `geom_label()` (@teunbrand and @steveharoz, #5365):
6+
* The `linewidth` aesthetic is now applied and replaces the `label.size`
7+
argument.
8+
* The `linetype` aesthetic is now applied.
9+
* New `border.colour` argument to set the colour of borders.
10+
* New `text.colour` argument to set the colour of text.
11+
* New `element_point()` and `element_polygon()` that can be given to
12+
`theme(point, polygon)` as an extension point (@teunbrand, #6248).
13+
* Turned off fallback for `size` to `linewidth` translation in
14+
`geom_bar()`/`geom_col()` (#4848).
15+
* `coord_radial()` now displays no axis instead of throwing an error when
16+
a scale has no breaks (@teunbrand, #6271).
17+
* The `fatten` argument has been deprecated in `geom_boxplot()`,
18+
`geom_crossbar()` and `geom_pointrange()` (@teunbrand, #4881).
19+
* Axis labels are now preserved better when using `coord_sf(expand = TRUE)` and
20+
graticule lines are straight but do not meet the edge (@teunbrand, #2985).
21+
* Attempt to boost detail in `coord_polar()` and `coord_radial()` near the
22+
center (@teunbrand, #5023)
523
* Scale names, guide titles and aesthetic labels can now accept functions
624
(@teunbrand, #4313)
725
* Binned scales with zero-width data expand the default limits by 0.1
@@ -285,6 +303,11 @@
285303
* Munching in `coord_polar()` and `coord_radial()` now adds more detail,
286304
particularly for data-points with a low radius near the center
287305
(@teunbrand, #5023).
306+
* All scales now expose the `aesthetics` parameter (@teunbrand, #5841)
307+
* New `theme(legend.key.justification)` to control the alignment of legend keys
308+
(@teunbrand, #3669).
309+
* Added `scale_{x/y}_time(date_breaks, date_minor_breaks, date_labels)`
310+
(@teunbrand, #4335).
288311

289312
# ggplot2 3.5.1
290313

R/coord-radial.R

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,18 @@ CoordRadial <- ggproto("CoordRadial", Coord,
250250
names(gdefs) <- aesthetics
251251

252252
# Train theta guide
253-
for (t in intersect(c("theta", "theta.sec"), aesthetics[!empty])) {
254-
gdefs[[t]] <- guides[[t]]$train(gdefs[[t]], panel_params[[t]])
255-
gdefs[[t]] <- guides[[t]]$transform(gdefs[[t]], self, panel_params)
256-
gdefs[[t]] <- guides[[t]]$get_layer_key(gdefs[[t]], layers)
257-
}
253+
t <- intersect(c("theta", "theta.sec"), aesthetics[!empty])
254+
gdefs[t] <- Map(
255+
function(guide, guide_param, scale) {
256+
guide_param$theme_suffix <- "theta"
257+
guide_param <- guide$train(guide_param, scale)
258+
guide_param <- guide$transform(guide_param, self, panel_params)
259+
guide_param <- guide$get_layer_key(guide_param, layers)
260+
},
261+
guide = guides[t],
262+
guide_param = gdefs[t],
263+
scale = panel_params[t]
264+
)
258265

259266
if (!isFALSE(self$r_axis_inside)) {
260267
# For radial axis, we need to pretend that rotation starts at 0 and
@@ -269,17 +276,18 @@ CoordRadial <- ggproto("CoordRadial", Coord,
269276
temp <- modify_list(panel_params, mod)
270277

271278
# Train radial guide
272-
for (r in intersect(c("r", "r.sec"), aesthetics[!empty])) {
273-
gdefs[[r]] <- guides[[r]]$train(gdefs[[r]], panel_params[[r]])
274-
gdefs[[r]] <- guides[[r]]$transform(gdefs[[r]], self, temp) # Use temp
275-
gdefs[[r]] <- guides[[r]]$get_layer_key(gdefs[[r]], layers)
276-
}
277-
278-
# Set theme suffixes
279-
gdefs$theta$theme_suffix <- "theta"
280-
gdefs$theta.sec$theme_suffix <- "theta"
281-
gdefs$r$theme_suffix <- "r"
282-
gdefs$r.sec$theme_suffix <- "r"
279+
r <- intersect(c("r", "r.sec"), aesthetics[!empty])
280+
gdefs[r] <- Map(
281+
function(guide, guide_param, scale) {
282+
guide_param$theme_suffix <- "r"
283+
guide_param <- guide$train(guide_param, scale)
284+
guide_param <- guide$transform(guide_param, self, temp)
285+
guide_param <- guide$get_layer_key(guide_param, layers)
286+
},
287+
guide = guides[r],
288+
guide_param = gdefs[r],
289+
scale = panel_params[r]
290+
)
283291

284292
panel_params$guides$update_params(gdefs)
285293
panel_params

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")?

R/facet-grid-.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ FacetGrid <- ggproto("FacetGrid", Facet,
309309
params$margins
310310
)
311311
# Apply recycling on original data to fit margins
312-
data <- vec_slice(data, facet_vals$.index)
312+
# We're using base subsetting here because `data` might have a superclass
313+
# that isn't handled well by vctrs::vec_slice
314+
data <- data[facet_vals$.index, , drop = FALSE]
313315
facet_vals$.index <- NULL
314316
}
315317

R/geom-bar.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,5 @@ GeomBar <- ggproto("GeomBar", GeomRect,
155155
flip_data(data, params$flipped_aes)
156156
},
157157

158-
rename_size = TRUE
158+
rename_size = FALSE
159159
)

R/geom-boxplot.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
239239
extra_params = c("na.rm", "orientation", "outliers"),
240240

241241
setup_params = function(data, params) {
242+
if ("fatten" %in% names(params)) {
243+
deprecate_soft0(
244+
"3.6.0", "geom_boxplot(fatten)",
245+
"geom_boxplot(median.linewidth)"
246+
)
247+
} else {
248+
# For backward compatibility reasons
249+
params$fatten <- 2
250+
}
242251
params$flipped_aes <- has_flipped_aes(data, params)
243252
params
244253
},

R/geom-crossbar.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ geom_crossbar <- function(mapping = NULL, data = NULL,
1717
box.color = NULL,
1818
box.linetype = NULL,
1919
box.linewidth = NULL,
20-
fatten = 2.5,
20+
fatten = deprecated(),
2121
na.rm = FALSE,
2222
orientation = NA,
2323
show.legend = NA,
@@ -60,6 +60,15 @@ geom_crossbar <- function(mapping = NULL, data = NULL,
6060
#' @export
6161
GeomCrossbar <- ggproto("GeomCrossbar", Geom,
6262
setup_params = function(data, params) {
63+
if (lifecycle::is_present(params$fatten)) {
64+
deprecate_soft0(
65+
"3.6.0", "geom_crossbar(fatten)",
66+
"geom_crossbar(middle.linewidth)"
67+
)
68+
} else {
69+
# For backward compatibility reasons
70+
params$fatten <- 2.5
71+
}
6372
GeomErrorbar$setup_params(data, params)
6473
},
6574

R/geom-label.R

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,36 @@
22
#' @rdname geom_text
33
#' @param label.padding Amount of padding around label. Defaults to 0.25 lines.
44
#' @param label.r Radius of rounded corners. Defaults to 0.15 lines.
5-
#' @param label.size Size of label border, in mm.
5+
#' @param label.size `r lifecycle::badge("deprecated")` Replaced by the
6+
#' `linewidth` aesthetic. Size of label border, in mm.
7+
#' @param border.colour,border.color Colour of label border. When `NULL`
8+
#' (default), the `colour` aesthetic determines the colour of the label border.
9+
#' `border.color` is an alias for `border.colour`.
10+
#' @param text.colour,text.color Colour of the text. When `NULL` (default), the
11+
#' `colour` aesthetic determines the colour of the text. `text.color` is an
12+
#' alias for `text.colour`.
613
geom_label <- function(mapping = NULL, data = NULL,
714
stat = "identity", position = "nudge",
815
...,
916
parse = FALSE,
1017
label.padding = unit(0.25, "lines"),
1118
label.r = unit(0.15, "lines"),
12-
label.size = 0.25,
19+
label.size = deprecated(),
20+
border.colour = NULL,
21+
border.color = NULL,
22+
text.colour = NULL,
23+
text.color = NULL,
1324
size.unit = "mm",
1425
na.rm = FALSE,
1526
show.legend = NA,
1627
inherit.aes = TRUE) {
1728

29+
extra_args <- list2(...)
30+
if (lifecycle::is_present(label.size)) {
31+
deprecate_warn0("3.5.0", "geom_label(label.size)", "geom_label(linewidth)")
32+
extra_args$linewidth <- extra_args$linewidth %||% label.size
33+
}
34+
1835
layer(
1936
data = data,
2037
mapping = mapping,
@@ -27,10 +44,11 @@ geom_label <- function(mapping = NULL, data = NULL,
2744
parse = parse,
2845
label.padding = label.padding,
2946
label.r = label.r,
30-
label.size = label.size,
3147
size.unit = size.unit,
48+
border.colour = border.color %||% border.colour,
49+
text.colour = text.color %||% text.colour,
3250
na.rm = na.rm,
33-
...
51+
!!!extra_args
3452
)
3553
)
3654
}
@@ -49,14 +67,17 @@ GeomLabel <- ggproto("GeomLabel", Geom,
4967
size = from_theme(fontsize),
5068
angle = 0,
5169
hjust = 0.5, vjust = 0.5, alpha = NA, fontface = 1,
52-
lineheight = 1.2
70+
lineheight = 1.2,
71+
linewidth = from_theme(borderwidth * 0.5),
72+
linetype = from_theme(bordertype)
5373
),
5474

5575
draw_panel = function(self, data, panel_params, coord, parse = FALSE,
5676
na.rm = FALSE,
5777
label.padding = unit(0.25, "lines"),
5878
label.r = unit(0.15, "lines"),
59-
label.size = 0.25,
79+
border.colour = NULL,
80+
text.colour = NULL,
6081
size.unit = "mm") {
6182
lab <- data$label
6283
if (parse) {
@@ -71,6 +92,12 @@ GeomLabel <- ggproto("GeomLabel", Geom,
7192
}
7293

7394
size.unit <- resolve_text_unit(size.unit)
95+
data$text.colour <- text.colour %||% data$colour
96+
data$border.colour <- border.colour %||% data$colour
97+
data$border.colour[data$linewidth == 0] <- NA
98+
data$fill <- fill_alpha(data$fill, data$alpha)
99+
data$size <- data$size * size.unit
100+
74101

75102
grobs <- lapply(seq_len(nrow(data)), function(i) {
76103
row <- data[i, , drop = FALSE]
@@ -82,16 +109,17 @@ GeomLabel <- ggproto("GeomLabel", Geom,
82109
r = label.r,
83110
angle = row$angle,
84111
text.gp = gg_par(
85-
col = row$colour,
86-
fontsize = row$size * size.unit,
112+
col = row$text.colour,
113+
fontsize = row$size,
87114
fontfamily = row$family,
88115
fontface = row$fontface,
89116
lineheight = row$lineheight
90117
),
91118
rect.gp = gg_par(
92-
col = if (isTRUE(all.equal(label.size, 0))) NA else row$colour,
93-
fill = fill_alpha(row$fill, row$alpha),
94-
lwd = label.size
119+
col = row$border.colour,
120+
fill = row$fill,
121+
lwd = row$linewidth,
122+
lty = row$linetype
95123
)
96124
)
97125
})

R/geom-linerange.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#' @eval rd_orientation()
77
#'
88
#' @eval rd_aesthetics("geom", "linerange", "Note that `geom_pointrange()` also understands `size` for the size of the points.")
9-
#' @param fatten A multiplicative factor used to increase the size of the
10-
#' middle bar in `geom_crossbar()` and the middle point in
11-
#' `geom_pointrange()`.
9+
#' @param fatten `r lifecycle::badge("deprecated")` A multiplicative factor
10+
#' used to increase the size of the middle bar in `geom_crossbar()` and the
11+
#' middle point in `geom_pointrange()`.
1212
#' @seealso
1313
#' [stat_summary()] for examples of these guys in use,
1414
#' [geom_smooth()] for continuous analogue

0 commit comments

Comments
 (0)