Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable panel size (space) for facet_wrap() #5956

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

teunbrand
Copy link
Collaborator

This PR addresses a topic discussed off-github.

To recap, there exist ggforce::facet_rows() and ggforce::facet_cols() that allow variable space space for panels, but confines the layout to a single row or column respectively.
We realised that it would be straightforward this in ggplot2 after #5917 would be implemented.
There'd need to be a space argument that needs to be passed on, and when space = "free_x/y", we'd need to restrict the nrow/ncol layout options. That is what this PR does.

Some examples. 1 row, free column-width:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()

p + facet_wrap(~ drv, space = "free_x", scales = "free_x")

1 column, free row-height:

p + facet_wrap(~ drv, space = "free_y", scales = "free_y")

Giving space = "free_x/y" and ncol/nrow throws a warning and ncol/nrow are ignored.

p + facet_wrap(~ drv, space = "free_x", scales = "free_x",
               ncol = 2, nrow = 1)
#> Warning: Cannot use `space = "free_x"` with custom `nrow` or `ncol`.

Created on 2024-06-25 with reprex v2.1.0

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.

None yet

1 participant