changing multiple line title in multiplot ggplot2 using grid.arrange

前端 未结 3 1884
余生分开走
余生分开走 2020-12-19 21:22

I have followed the advice on the discussion

changing title in multiplot ggplot2 using grid.arrange

but my 2-line title doesn\'t change the font size.

相关标签:
3条回答
  • 2020-12-19 22:01

    You could go in a different direction and use ggplot2 latest build from github:

    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
    

    This was added pretty recently here: https://github.com/hadley/ggplot2/pull/1582

    let me know if it works!

    0 讨论(0)
  • 2020-12-19 22:13

    Here's one possibility,

    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")))
    
    0 讨论(0)
  • 2020-12-19 22:16

    The paste command provides newline separation that currently (December 2015) is correctly interpreted by gridExtra:

    heres_the_tricky_part <- paste("mainTitle", "subTitle", sep="\n")
    
    grid.arrange(plot1, plot2, nrow=1, ncol=2, top=heres_the_tricky_part )
    
    0 讨论(0)
提交回复
热议问题