I'd like to change the color of the text in my title for a grid.arrange plot.
Given data like this:
X<-c(1,2,3,4,5)
Y<-c(2,3,6,7,8)
Y2<-c(5,6,7,8,2)
DF<-data.frame(X,Y,Y2)
g1<-ggplot(data=DF, aes(x=X,y=Y)) + geom_line(color='black')
g2<-ggplot(data=DF,aes(x=X,y=Y2)) + geom_line(color="black")
grid.arrange(arrangeGrob(g1,g2,ncol=2,top="My Title"))
How can I change the text color of "My Title" to a color other than black?
To change the color you can use the textGrob
function from the grid
package and use the gpar
argument to specify the color:
top=textGrob("My Title", gp=gpar(col="blue"))
See the gpar
help for a list of other options such as font size, font face, etc. that can be adjusted in the same way.
I thought this question must be a duplicate, but I haven't found a question that addresses changing the color specifically, though there are some questions (here and here, for example), that use other gpar
options. If anyone is aware of a duplicate, please mark it.