Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


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

# ggplot2 4.0.0

Expand Down
7 changes: 5 additions & 2 deletions R/stat-boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
StatBoxplot <- ggproto("StatBoxplot", Stat,
required_aes = c("y|x"),
non_missing_aes = "weight",
optional_aes = "width",
# either the x or y aesthetic will get dropped during
# statistical transformation, depending on the orientation
dropped_aes = c("x", "y", "weight"),
Expand Down Expand Up @@ -69,9 +70,11 @@ StatBoxplot <- ggproto("StatBoxplot", Stat,
if (any(outliers)) {
stats[c(1, 5)] <- range(c(stats[2:4], data$y[!outliers]), na.rm = TRUE)
}

if (vec_unique_count(data$x) > 1)
if (length(data$width) > 0L) {
width <- data$width[1L]
} else if (vec_unique_count(data$x) > 1) {
width <- diff(range(data$x)) * 0.9
}

df <- data_frame0(!!!as.list(stats))
df$outliers <- list(data$y[outliers])
Expand Down
Loading