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.
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!
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")))
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 )