gpt4 book ai didi

R:网格布局标题

转载 作者:行者123 更新时间:2023-12-04 00:08:02 27 4
gpt4 key购买 nike

我正在使用 grid 包来显示这样的图数组:

layout <- grid.layout(2, 4)
pushViewport(viewport(layout = layout))
# print various plots

有没有办法为整个网格布局指定标题?

最佳答案

基于类似 SO 问题的虚拟示例:Place title of multiplot panel with ggplot2

  • 首先创建一个具有所需行数 + 1 个短行作为标题的布局:
    pushViewport(viewport(layout = grid.layout(3, 2, heights = unit(c(0.5, 5, 5), "null"))))   
  • 在那里创建一些图:
    print(ggplot(mtcars, aes(hp)) + geom_histogram(), vp = viewport(layout.pos.row = 2, layout.pos.col = 1:2))
    print(ggplot(mtcars, aes(wt)) + geom_histogram(), vp = viewport(layout.pos.row = 3, layout.pos.col = 1))
    print(ggplot(mtcars, aes(mpg)) + geom_histogram(), vp = viewport(layout.pos.row = 3, layout.pos.col = 2))
  • 将标题添加到顶行:
    grid.text("MAIN TITLE", vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2))

  • 导致:

    enter image description here

    关于R:网格布局标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10776139/

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