Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing multiple line title in multiplot ggplot2 using grid.arrange

Tags:

r

ggplot2

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.

1- should I state main in grid.arrange or do I use grid.arrange without main and then, add the following script

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

Thanks

Carol

like image 756
carol Avatar asked Oct 19 '25 01:10

carol


2 Answers

Here's one possibility,

enter image description here

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")))
like image 76
baptiste Avatar answered Oct 22 '25 04:10

baptiste


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!

like image 22
spsaaibi Avatar answered Oct 22 '25 04:10

spsaaibi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!