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`.
This PR addresses a topic discussed off-github.
To recap, there exist
ggforce::facet_rows()
andggforce::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 aspace
argument that needs to be passed on, and whenspace = "free_x/y"
, we'd need to restrict thenrow
/ncol
layout options. That is what this PR does.Some examples. 1 row, free column-width:
1 column, free row-height:
Giving
space = "free_x/y"
andncol
/nrow
throws a warning andncol
/nrow
are ignored.Created on 2024-06-25 with reprex v2.1.0