Skip to content

Commit c95dd03

Browse files
committed
Merge branch 'main' into after_stat_legend_data_resolving
2 parents f7a16e0 + 1bfb3c9 commit c95dd03

Some content is hidden

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

50 files changed

+908
-149
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# ggplot2 (development version)
22

3+
* New parameters for `geom_label()` (@teunbrand and @steveharoz, #5365):
4+
* The `linewidth` aesthetic is now applied and replaces the `label.size`
5+
argument.
6+
* The `linetype` aesthetic is now applied.
7+
* New `border.colour` argument to set the colour of borders.
8+
* New `text.colour` argument to set the colour of text.
9+
* New `element_point()` and `element_polygon()` that can be given to
10+
`theme(point, polygon)` as an extension point (@teunbrand, #6248).
11+
* Turned off fallback for `size` to `linewidth` translation in
12+
`geom_bar()`/`geom_col()` (#4848).
13+
* `coord_radial()` now displays no axis instead of throwing an error when
14+
a scale has no breaks (@teunbrand, #6271).
15+
* The `fatten` argument has been deprecated in `geom_boxplot()`,
16+
`geom_crossbar()` and `geom_pointrange()` (@teunbrand, #4881).
317
* Axis labels are now preserved better when using `coord_sf(expand = TRUE)` and
418
graticule lines are straight but do not meet the edge (@teunbrand, #2985).
519
* Attempt to boost detail in `coord_polar()` and `coord_radial()` near the
@@ -290,6 +304,10 @@
290304
* All scales now expose the `aesthetics` parameter (@teunbrand, #5841)
291305
* Staged expressions are handled more gracefully if legends cannot resolve them
292306
(@teunbrand, #6264).
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).
293311

294312
# ggplot2 3.5.1
295313

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/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

R/geom-point.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ GeomPoint <- ggproto("GeomPoint", Geom,
148148
),
149149

150150
draw_panel = function(self, data, panel_params, coord, na.rm = FALSE) {
151-
if (is.character(data$shape)) {
152-
data$shape <- translate_shape_string(data$shape)
153-
}
154-
151+
data$shape <- translate_shape_string(data$shape)
155152
coords <- coord$transform(data, panel_params)
156153
ggname("geom_point",
157154
pointsGrob(
@@ -176,7 +173,8 @@ GeomPoint <- ggproto("GeomPoint", Geom,
176173
#' given as a character vector into integers that are interpreted by the
177174
#' grid system.
178175
#'
179-
#' @param shape_string A character vector giving point shapes.
176+
#' @param shape_string A character vector giving point shapes. Non-character
177+
#' input will be returned.
180178
#'
181179
#' @return An integer vector with translated shapes.
182180
#' @export
@@ -188,6 +186,9 @@ GeomPoint <- ggproto("GeomPoint", Geom,
188186
#' # Strings with 1 or less characters are interpreted as symbols
189187
#' translate_shape_string(c("a", "b", "?"))
190188
translate_shape_string <- function(shape_string) {
189+
if (!is.character(shape_string)) {
190+
return(shape_string)
191+
}
191192
# strings of length 0 or 1 are interpreted as symbols by grid
192193
if (nchar(shape_string[1]) <= 1) {
193194
return(shape_string)

0 commit comments

Comments
 (0)