Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

main title in grid.arrange or arrangeGrob has a grey background

I am switching from ggplot2 1.0.1 and gridExtra 0.9.1 to the newest versions of these packages and struggle with some minor issues at the moment.

One problem is the title in a combined plot.

library(ggplot2)
library(gridExtra)
df <- data.frame(x=runif(100), y=runif(100))
p1 <- ggplot(df, aes(x,y)) + geom_point()
p2 <- ggplot(df, aes(x,y)) + geom_point()
a <- arrangeGrob(p1,p1,p2, layout_matrix=rbind(c(1,2),c(1,3)), top='my title')
plot(a)
ggsave('a.pdf', a)

in the older version, the parameter was called main and I had to use print to plot my graphics a. Now, when I save the graph, everything is fine. But the plot(a) graph has the light grey grid background behind the my title. In the saved pdf file, the background is white again.

I also tried to use grid.arrange but I don't want to print the plot directly when executing. Thats why I use the two step approach by saving the graph in a variable and then plot it.

So, how do I get a white background when plot(a)?

like image 991
drmariod Avatar asked Sep 26 '22 18:09

drmariod


1 Answers

Use grid.draw. The plot method is for testing only.

library(grid)
grid.newpage() 
grid.draw(a)

resulting plot

like image 104
Roland Avatar answered Nov 15 '22 05:11

Roland