-
Notifications
You must be signed in to change notification settings - Fork 165
Description
my orginal require is splicing a grob object and a ggplot2 object,but get some error
then i tried two ways to fix it:
first way: covert pheatmap to ggplot by ggplotify::as.ggplot
p1 <- pheatmap::pheatmap(t(iris[1:50,1:4]))
p1 = ggplotify::as.ggplot(p1$gtable)
p2 <- ggplot(mtcars) + geom_boxplot(aes(factor(cyl), disp,fill = factor(cyl)));p2
library(ggplot2)
library(patchwork)
p1 +p2 + plot_layout(guides = 'collect')
image
plot_layout(guides = 'collect') doesn't work
##second way :convert ggplot to grob
p1 <- pheatmap::pheatmap(t(iris[1:50,1:4]))
p1_1 <- p1$gtable
p2 <- ggplot(mtcars) + geom_boxplot(aes(factor(cyl), disp,fill = factor(cyl)));p2
p2_1 <- ggplot_gtable(ggplot_build(p2))
p2_2 <- ggplotGrob(p2)
p1_1 + p2_1 #error
wrap_ggplot_grob(p1_1)+wrap_ggplot_grob(p2_2) #error
wrap_elements(p1_1) + wrap_elements(p2_2)+ plot_layout(guides = 'collect')
no error but plot_layout(guides = 'collect') still not work
image
#ggplot2 object convert to grob then turn back to ggplot2 ,it doesn't work neither。
p2 + p2 + plot_layout(guides = 'collect')
as.ggplot(p2_2) +as.ggplot(p2_2) +plot_layout(guides = 'collect')
Activity
thomasp85 commentedon Jun 17, 2020
I don't think you can expect patchwork to work with ggplotify etc