【问题标题】:changing multiple line title in multiplot ggplot2 using grid.arrange使用 grid.arrange 在 multiplot ggplot2 中更改多行标题
【发布时间】:2015-07-25 18:54:41
【问题描述】:

我已经听从了讨论中的建议

changing title in multiplot ggplot2 using grid.arrange

但我的 2 行标题不会改变字体大小。

1- 我应该在 grid.arrange 中声明 main 还是使用不带 main 的 grid.arrange 然后添加以下脚本

main=textGrob(paste("titleLine1", "titleLine2", sep = "\n"),gp=gpar(fontsize=20))

谢谢

卡罗尔

【问题讨论】:

  • 是的,它有效。我在一行中分别使用了grid.arrange和第二行的textGrob。
  • 如果我想在第一行显示 title1 并且 for ex fontsize = 18 和 title2 在第二行显示 fontsize = 16,应该怎么做?
  • 请注意,对于 gridExtra 的 v>=2.0.0,main 参数已重命名为 top

标签: r ggplot2


【解决方案1】:

这是一种可能性,

library(grid); library(gridExtra)
tg <- textGrob("Title Goes Here", gp=gpar(fontsize=30))
sg <- textGrob("more subtle subtitle ", gp=gpar(fontsize=15, fontface=3L))
margin <- unit(0.5, "line")
grid.newpage()
grid.arrange(tg, sg, rectGrob(), 
             heights = unit.c(grobHeight(tg) + 1.2*margin, 
                              grobHeight(sg) + margin, 
                              unit(1,"null")))

【讨论】:

    【解决方案2】:

    你可以换个方向,使用来自githubggplot2最新版本:

    library(ggplot2) # (github version) devtools::install_github("hadley/ggplot2")
    
    p <-  ggplot(cars, aes(x=speed, y=dist))
    p <- p + theme_bw()
    p <- p + geom_bar(fill="blue", stat="identity")
    p <- p + labs(title="Fast Cars",
                  subtitle="Are more Fun")
    p <- p + theme(axis.text.x=element_text(angle=90, hjust=0, vjust=1)) 
    p <- p + theme(plot.title=element_text(size=30, hjust=0.5, face="bold", colour="darkgreen", vjust=-1))
    p <- p + theme(plot.subtitle=element_text(size=20, hjust=0.5, face="italic", color="darkred"))
    p
    

    这是最近在此处添加的: https://github.com/hadley/ggplot2/pull/1582

    让我知道它是否有效!

    【讨论】:

      【解决方案3】:

      粘贴命令提供了当前(2015 年 12 月)被 gridExtra 正确解释的换行符分隔:

      heres_the_tricky_part <- paste("mainTitle", "subTitle", sep="\n")
      
      grid.arrange(plot1, plot2, nrow=1, ncol=2, top=heres_the_tricky_part )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-26
        • 1970-01-01
        • 2015-03-30
        • 1970-01-01
        • 2021-01-02
        • 2019-03-29
        • 2013-02-03
        相关资源
        最近更新 更多