Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit style of grid.arrange title. Bold, italic etc. R

I am creating a multi plot in R using grid.arrange, and wanted to change my title so that it is bold (and italic if possible).

As this is a general question, I will not include the code for my plots, but the code I am using to make my multi plot is:

grid.arrange(g1, g3, g4+theme(legend.position="none"),mylegend, top="Test title",
             layout_matrix=matrix(c(1,1,2,3,4,4), ncol=2, byrow=TRUE),heights=c(1,1.5,0.3))

Are there any additional arguments which can be passed to the top argument to change the font face?

like image 758
sym246 Avatar asked Mar 15 '16 10:03

sym246


1 Answers

I've worked it out myself..

You can use the text_grob function to create a text element, which can then be passed to the top function of grid.arrange.

For example,

##title1=textGrob("Test title", gp=gpar(fontface="bold")) ## this does not work anymore

title1=text_grob(main, size = 15, face = "bold")   #### this worked for me
grid.arrange(g1, g3, g4+theme(legend.position="none"),mylegend, top=title1, ncol=2, byrow=TRUE),heights=c(1,1.5,0.3))

Just a small update:

Instead of using text

textGrob

use text_grob from ggpubr package

like image 67
sym246 Avatar answered Oct 18 '22 11:10

sym246