我有一个返回拼图的函数,但我不能对其进行任何更改。我想在上面添加一个rectGrob()。当我尝试这样做时,我删除了两个图。
library(gridExtra)
library(patchwork)
library(ggplot2)
p1 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()
p2 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point()
p3 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width), col = 'blue') + geom_point()
p <- p1 + p2 + p3
grob_top <- grobTree(rectGrob(gp=gpar(fill='#F0F0F0',col= 'black')), textGrob('P1,P2, P3'))
grid.arrange(grob_top, p, heights = c(0.1, 0.9))发布于 2020-05-08 17:27:57
使用patchwork::wrap_elements()比使用gridExtra::grid.arrange()效果更好
patchwork::wrap_elements(grob_top) /
patchwork::wrap_elements(p) /
patchwork::wrap_elements(p) +
patchwork::plot_layout(ncol = 1, heights = c(0.1, 0.45, 0.45))发布于 2020-05-07 23:07:22
我认为你想要:
grid.arrange(grob_top,
p,
nrow = 2,
heights = c(0.1, 0.9))

https://stackoverflow.com/questions/61658935
复制相似问题