-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
Description
Currently, the geom_boxplot
does not fully respect the width
aesthetic when using aes(width = ...)
. This makes it difficult to control the exact width of boxplots in cases where variable widths are required.
n <- vapply(
split(mpg, ~cyl),
function(d) length(unique(d$class)),
integer(1L)
)
dplyr::mutate(mpg,
width = length(unique(class)),
median = length(unique(class)) / 2L,
.by = cyl
) |>
ggplot() +
geom_boxplot(
aes(median, hwy, group = median, width = width)
) +
facet_wrap(vars(cyl), nrow = 1L, space = "free_x", scales = "free_x") +
ggh4x::facetted_pos_scales(
lapply(n, function(max) scale_x_continuous(limits = c(0, max)))
)
