我想知道如何将一个 grob 对象(表格)排列在另一个对象中。考虑以下示例:
library(ggplot2)
library(gridExtra)
p1 <- qplot(data=mtcars, x = mpg, y = hp, facets = ~ hp, geom="point")
t1 <- tableGrob(head(mtcars))
print(arrangeGrob(p1, t1))
这会产生:
我想做的是将表格放在内部另一个对象中,如下所示:
是否可以使用 gridArrange
或 grid
和/或 gridExtra
中的其他方法来做到这一点?
最佳答案
这是使用网格函数的一种可能性:
png("SO.png", width = 1440, height = 720)
plot(p1)
vp <- viewport(x = 0.95, y = 0.02,
width = unit(0.4, "npc"), height = unit(0.2, "npc"),
just = c("right", "bottom"))
pushViewport(vp)
grid.draw(t1)
dev.off()
关于r - 如何使用 r 中的 ggplot2 和 gridExtra 包将一个 grob 对象排列在另一个对象中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30128467/