gpt4 book ai didi

r - 在 R 中的绘图网格中添加边框

转载 作者:行者123 更新时间:2023-12-04 11:23:54 31 4
gpt4 key购买 nike

我使用 ggplot 创建了一系列图并将它们打印在网格中。我想在整个网格周围添加一个边框,这样当我将图像插入演示文稿时,它就会被明确定义。

这是我正在使用的网格和打印命令的创建。我已经导入了所有必要的包。

library(grid)
pushViewport(viewport(gp=gpar(col="white"),
layout = grid.layout(4, 2, heights = unit(c(0.5,5,5,5), "null"))))
grid.text("Summer Clear Day- August 2, 2012",
vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2))
grid.frame(gp=gpar(col="white"), draw=TRUE)
print(tot, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
print(gh, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
print(dir, vp = viewport(layout.pos.row = 3, layout.pos.col = 1))
print(ir, vp = viewport(layout.pos.row = 3, layout.pos.col = 2))
print(dh, vp = viewport(layout.pos.row = 4, layout.pos.col = 1))
print(uv, vp = viewport(layout.pos.row = 4, layout.pos.col = 2))

grid.frame 似乎没有做任何事情。我的背景是黑色的,所以我希望在它周围创建一个白色边框。

最佳答案

您可以使用 grid.rect例如。我会把它放在一个单独的 viewport在绘制你的情节之前。我是说:

  • 我推第一个视口(viewport),绘制矩形(框架)
  • 我插入第二个视口(viewport),我创造了你所有的情节。
  • 我弹出我的 2 个视口(viewport)

  • enter image description here
    pushViewport(plotViewport(c(5,5,5,5)))
    grid.rect()
    grid.rect(width=unit(1, "npc")-unit(0.5,'lines'),
    height=unit(1, "npc")-unit(0.5,'lines'))
    pushViewport(plotViewport(c(1,1,1,1),
    layout = grid.layout(4, 2,
    heights = unit(c(1,5,5,5), "null"))))
    grid.text("Summer Clear Day- August 2, 2012",
    vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2))
    k1 <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot()

    print(k1, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
    print(k1, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
    print(k1, vp = viewport(layout.pos.row = 3, layout.pos.col = 1))
    print(k1, vp = viewport(layout.pos.row = 3, layout.pos.col = 2))
    print(k1, vp = viewport(layout.pos.row = 4, layout.pos.col = 1))
    print(k1, vp = viewport(layout.pos.row = 4, layout.pos.col = 2))
    upViewport(2)

    关于r - 在 R 中的绘图网格中添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15485718/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com