Hello,
Awesome package this! I would like to know if there could be a way to determine the number of patches of the current plot and/or access information on the layout. This would allow, among other things, looping over these patches.
My attempt at accessing these attributes
library(ggplot2)
library(patchwork)
p<-ggplot(mtcars,aes(mpg, disp)) +
geom_col()
p1 <- ggplot(mtcars,aes(disp, mpg)) +
geom_col()
p2<- p + p1
str(p2)
This contains the required information but there is no way to extract the number 2 without resorting to a RegEx based grep
A patchwork composed of 2 patches
- Autotagging is turned off
- Guides are kept
Layout:
2 patch areas, spanning 2 columns and 1 rows
t l b r
1: 1 1 1 1
2: 1 2 1 2
length on the other hand gives 10 which is not ideal.
A solution
The above however will return only one plot if the plots are identical giving an incorrect length of 1.
p3 <- p + p
length(p3$patches$plots)
Thank you very much and apologies if this is documented/or exists somewhere else already ( I could not find them).
NelsonGon
Hello,
Awesome package this! I would like to know if there could be a way to determine the number of patches of the current plot and/or access information on the layout. This would allow, among other things, looping over these patches.
My attempt at accessing these attributes
This contains the required information but there is no way to extract the number 2 without resorting to a RegEx based
greplengthon the other hand gives 10 which is not ideal.A solution
The above however will return only one plot if the plots are identical giving an incorrect length of 1.
Thank you very much and apologies if this is documented/or exists somewhere else already ( I could not find them).
NelsonGon