Skip to content

Commit 4b7acf5

Browse files
committed
Fallback to use size if linewidth is missing in input data
1 parent cc4ff9b commit 4b7acf5

12 files changed

+30
-10
lines changed

R/geom-.r

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,11 @@ check_aesthetics <- function(x, n) {
237237
"x" = "Fix the following mappings: {.col {names(which(!good))}}"
238238
))
239239
}
240+
241+
check_linewidth <- function(data, name) {
242+
if (is.null(data$linewidth) && !is.null(data$size)) {
243+
lifecycle::deprecate_soft("3.4.0", I(paste0("Using the `size` aesthietic with ", name)), I("the `linewidth` aesthetic"))
244+
data$linewidth <- data$size
245+
}
246+
data
247+
}

R/geom-boxplot.r

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
212212
outlier.size = 1.5, outlier.stroke = 0.5,
213213
outlier.alpha = NULL, notch = FALSE, notchwidth = 0.5,
214214
varwidth = FALSE, flipped_aes = FALSE) {
215+
data <- check_linewidth(data, snake_class(self))
215216
data <- flip_data(data, flipped_aes)
216217
# this may occur when using geom_boxplot(stat = "identity")
217218
if (nrow(data) != 1) {

R/geom-crossbar.r

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ GeomCrossbar <- ggproto("GeomCrossbar", Geom,
4747

4848
draw_key = draw_key_crossbar,
4949

50-
draw_panel = function(data, panel_params, coord, lineend = "butt",
50+
draw_panel = function(self, data, panel_params, coord, lineend = "butt",
5151
linejoin = "mitre", fatten = 2.5, width = NULL,
5252
flipped_aes = FALSE) {
53+
data <- check_linewidth(data, snake_class(self))
5354
data <- flip_data(data, flipped_aes)
5455

5556
middle <- transform(data, x = xmin, xend = xmax, yend = y, linewidth = linewidth * fatten, alpha = NA)

R/geom-errorbar.r

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ GeomErrorbar <- ggproto("GeomErrorbar", Geom,
5252
flip_data(data, params$flipped_aes)
5353
},
5454

55-
draw_panel = function(data, panel_params, coord, lineend = "butt", width = NULL, flipped_aes = FALSE) {
55+
draw_panel = function(self, data, panel_params, coord, lineend = "butt",
56+
width = NULL, flipped_aes = FALSE) {
57+
data <- check_linewidth(data, snake_class(self))
5658
data <- flip_data(data, flipped_aes)
5759
x <- vec_interleave(data$xmin, data$xmax, NA, data$x, data$x, NA, data$xmin, data$xmax)
5860
y <- vec_interleave(data$ymax, data$ymax, NA, data$ymax, data$ymin, NA, data$ymin, data$ymin)

R/geom-errorbarh.r

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ GeomErrorbarh <- ggproto("GeomErrorbarh", Geom,
6767
)
6868
},
6969

70-
draw_panel = function(data, panel_params, coord, height = NULL, lineend = "butt") {
70+
draw_panel = function(self, data, panel_params, coord, height = NULL, lineend = "butt") {
71+
data <- check_linewidth(data, snake_class(self))
7172
GeomPath$draw_panel(data_frame0(
7273
x = vec_interleave(data$xmax, data$xmax, NA, data$xmax, data$xmin, NA, data$xmin, data$xmin),
7374
y = vec_interleave(data$ymin, data$ymax, NA, data$y, data$y, NA, data$ymin, data$ymax),

R/geom-hex.r

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ geom_hex <- function(mapping = NULL, data = NULL,
5454
#' @usage NULL
5555
#' @export
5656
GeomHex <- ggproto("GeomHex", Geom,
57-
draw_group = function(data, panel_params, coord, lineend = "butt",
57+
draw_group = function(self, data, panel_params, coord, lineend = "butt",
5858
linejoin = "mitre", linemitre = 10) {
59+
data <- check_linewidth(data, snake_class(self))
5960
if (empty(data)) {
6061
return(zeroGrob())
6162
}

R/geom-path.r

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ GeomPath <- ggproto("GeomPath", Geom,
149149
draw_panel = function(self, data, panel_params, coord, arrow = NULL,
150150
lineend = "butt", linejoin = "round", linemitre = 10,
151151
na.rm = FALSE) {
152+
data <- check_linewidth(data, snake_class(self))
152153
if (!anyDuplicated(data$group)) {
153154
cli::cli_inform(c(
154155
"{.fn {snake_class(self)}}: Each group consists of only one observation.",
@@ -170,7 +171,7 @@ GeomPath <- ggproto("GeomPath", Geom,
170171
linetype <- unique0(df$linetype)
171172
data_frame0(
172173
solid = identical(linetype, 1) || identical(linetype, "solid"),
173-
constant = nrow(unique0(df[, names(data) %in% c("alpha", "colour", "linewidth", "linetype")])) == 1,
174+
constant = nrow(unique0(df[, names(df) %in% c("alpha", "colour", "linewidth", "linetype")])) == 1,
174175
.size = 1
175176
)
176177
})

R/geom-polygon.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ geom_polygon <- function(mapping = NULL, data = NULL,
107107
#' @usage NULL
108108
#' @export
109109
GeomPolygon <- ggproto("GeomPolygon", Geom,
110-
draw_panel = function(data, panel_params, coord, rule = "evenodd", lineend = "butt",
111-
linejoin = "round", linemitre = 10) {
110+
draw_panel = function(self, data, panel_params, coord, rule = "evenodd",
111+
lineend = "butt", linejoin = "round", linemitre = 10) {
112+
data <- check_linewidth(data, snake_class(self))
112113
n <- nrow(data)
113114
if (n == 1) return(zeroGrob())
114115

R/geom-rect.r

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ GeomRect <- ggproto("GeomRect", Geom,
3434
required_aes = c("xmin", "xmax", "ymin", "ymax"),
3535

3636
draw_panel = function(self, data, panel_params, coord, lineend = "butt", linejoin = "mitre") {
37+
data <- check_linewidth(data, snake_class(self))
3738
if (!coord$is_linear()) {
3839
aesthetics <- setdiff(
3940
names(data), c("x", "y", "xmin", "xmax", "ymin", "ymax")

R/geom-ribbon.r

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
119119
data
120120
},
121121

122-
draw_group = function(data, panel_params, coord, lineend = "butt",
122+
draw_group = function(self, data, panel_params, coord, lineend = "butt",
123123
linejoin = "round", linemitre = 10, na.rm = FALSE,
124124
flipped_aes = FALSE, outline.type = "both") {
125+
data <- check_linewidth(data, snake_class(self))
125126
data <- flip_data(data, flipped_aes)
126127
if (na.rm) data <- data[stats::complete.cases(data[c("x", "ymin", "ymax")]), ]
127128
data <- data[order(data$group), ]

R/geom-rug.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ geom_rug <- function(mapping = NULL, data = NULL,
8888
GeomRug <- ggproto("GeomRug", Geom,
8989
optional_aes = c("x", "y"),
9090

91-
draw_panel = function(data, panel_params, coord, lineend = "butt", sides = "bl",
92-
outside = FALSE, length = unit(0.03, "npc")) {
91+
draw_panel = function(self, data, panel_params, coord, lineend = "butt",
92+
sides = "bl", outside = FALSE, length = unit(0.03, "npc")) {
93+
data <- check_linewidth(data, snake_class(self))
9394
if (!inherits(length, "unit")) {
9495
cli::cli_abort("{.arg length} must be a {.cls unit} object.")
9596
}

R/geom-segment.r

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ GeomSegment <- ggproto("GeomSegment", Geom,
107107
default_aes = aes(colour = "black", linewidth = 0.5, linetype = 1, alpha = NA),
108108
draw_panel = function(self, data, panel_params, coord, arrow = NULL, arrow.fill = NULL,
109109
lineend = "butt", linejoin = "round", na.rm = FALSE) {
110+
data <- check_linewidth(data, snake_class(self))
110111
data <- remove_missing(data, na.rm = na.rm,
111112
c("x", "y", "xend", "yend", "linetype", "linewidth", "shape"),
112113
name = "geom_segment"

0 commit comments

Comments
 (0)