Skip to content

Commit 6de07af

Browse files
Yunuuuuteunbrand
andauthored
fix: respect width aesthetic (#6576)
* fix: respect `width` aesthetic * Apply suggestion from @teunbrand Co-authored-by: Teun van den Brand <[email protected]> * feat(StatBoxplot): support width as an optional aesthetic * add news bullet --------- Co-authored-by: Teun van den Brand <[email protected]> Co-authored-by: Teun van den Brand <[email protected]>
1 parent 6906324 commit 6de07af

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
* Allow `stat` in `geom_hline`, `geom_vline`, and `geom_abline`. (@sierrajohnson, #6559)
12+
* `stat_boxplot()` treats `width` as an optional aesthetic (@Yunuuuu, #6575)
1213

1314
# ggplot2 4.0.0
1415

R/stat-boxplot.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
StatBoxplot <- ggproto("StatBoxplot", Stat,
66
required_aes = c("y|x"),
77
non_missing_aes = "weight",
8+
optional_aes = "width",
89
# either the x or y aesthetic will get dropped during
910
# statistical transformation, depending on the orientation
1011
dropped_aes = c("x", "y", "weight"),
@@ -69,9 +70,11 @@ StatBoxplot <- ggproto("StatBoxplot", Stat,
6970
if (any(outliers)) {
7071
stats[c(1, 5)] <- range(c(stats[2:4], data$y[!outliers]), na.rm = TRUE)
7172
}
72-
73-
if (vec_unique_count(data$x) > 1)
73+
if (length(data$width) > 0L) {
74+
width <- data$width[1L]
75+
} else if (vec_unique_count(data$x) > 1) {
7476
width <- diff(range(data$x)) * 0.9
77+
}
7578

7679
df <- data_frame0(!!!as.list(stats))
7780
df$outliers <- list(data$y[outliers])

0 commit comments

Comments
 (0)