【问题标题】:How to arrange one grob object inside another with ggplot2 and gridExtra packages in r如何在 r 中使用 ggplot2 和 gridExtra 包将一个 grob 对象排列在另一个对象中
【发布时间】:2015-05-08 16:19:21
【问题描述】:

我想知道如何将一个 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))

这会产生:

我想做的是将表格放在另一个对象中,如下所示:

这是否可以使用gridArrangegrid 和/或gridExtra 中的其他一些方法来实现?

【问题讨论】:

标签: r ggplot2 gridextra


【解决方案1】:

这是使用网格函数的一种可能性:

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()

【讨论】:

    猜你喜欢
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    相关资源
    最近更新 更多