ggh4x
ggh4x copied to clipboard
`facet_grid_2()`: remove empty panels when `independent` is not set to `all`
Hi, thanks for the great package! I was wondering if it is possible to remove empty panels when using facet_grid2()
and setting independent
to either x
or y
instead of all
. Here's an example:
p <- ggplot(mpg, aes(displ, hwy)) + geom_point()
p + facet_grid2(cyl ~ drv, independent = 'y', scales = 'free_y')
Is there a way to remove empty panels as it would happen if using scales = 'free'
and independent = 'all'
?
Thanks!
Hi there, thanks for your suggestion. I think it'd make sense to include some option to drop empty panels. I don't know when I'll get around to doing it though. Currently, also with independent = "all"
, the panels are still drawn (you can see this when the panel background has a different fill than the plot background), so I don't think it is possible unless you wish to edit the ggplot grobs with {gtable}/{grid}. It'd probably makes most sense to add an argument like drop_empty_panel = TRUE/FALSE
to the function.
Thank you for your quick response! I didn't realize panels were drawn because I was using theme_minimal()
. The argument you suggest would be a good solution. Thanks!
I am aslo facing the same issue. When can we expect to have drop_empty_panel = TRUE/FALSE
argument?
That is a fair question that I don't know the answer to.
One can now do the following in the development version:
library(ggh4x)
#> Loading required package: ggplot2
ggplot(mpg, aes(displ, hwy)) + geom_point() +
facet_grid2(cyl ~ drv, render_empty = FALSE)
Created on 2023-07-15 by the reprex package (v2.0.1)