Skip to content

Conversation

Yunuuuu
Copy link
Contributor

@Yunuuuu Yunuuuu commented Aug 23, 2025

fix #6575

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)))
    )
image

Copy link
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to add optional_aes = "width" to the StatBoxplot class, if we're going to treat it as an aesthetic.

Copy link
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, thank you for adopting the proposals!
If you want, you can add a bulletpoint to the news file

@Yunuuuu
Copy link
Contributor Author

Yunuuuu commented Sep 25, 2025

It seems this PR is based on an older version of ggplot2, and the NEWS.md file conflicts with the current version. Therefore, I chose not to add the news item to NEWS.md.

@teunbrand
Copy link
Collaborator

The typical remedy for this type of situation is to update your fork and merge the (updated) main branch into the PR branch.
I'm happy to add the news bullet if you'd prefer that.

@Yunuuuu
Copy link
Contributor Author

Yunuuuu commented Sep 25, 2025

Thanks for the suggestion! Please feel free to add the news bullet directly.

@teunbrand teunbrand merged commit 6de07af into tidyverse:main Sep 25, 2025
13 checks passed
@teunbrand
Copy link
Collaborator

Thank you for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect width aes in geom_boxplot
2 participants