Closed fabern closed 4 years ago
Below example illustrates the issue in an alternative way by using gtable_filter()
:
library(ggplot2)
library(grid)
library(gtable)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
dat <- data.frame(x = c(1, 1, 1, 1, 1, 1),
y = c(1, 1, 1, 1, 1, 1),
a = c("a1", "a1", "a1", "a2", "a2", "a2"),
b = c("b1", "b2", "b3", "b1", "b2", "b3"))
p <- ggplot(dat, aes(x=x,y=y)) +
geom_point() +
facet_grid(vars(a),vars(b))
# Example B (requires dplyr)
p %>%
ggplotGrob() %>%
gtable_filter("^panel-1-1$", invert = TRUE) %>%
gtable_filter("^panel-1-2$", invert = TRUE) %>%
{grid.newpage(); grid.draw(.)}
Created on 2020-05-01 by the reprex package (v0.3.0)
The names of the
grobs
in thegtable
representing the panels created withfacet_grid()
are inconsistent. I would expect them to follow the patternpanel-[row.nr]-[col.nr]
, but they don't.Created on 2020-05-01 by the reprex package (v0.3.0)