I use grid.arrange() to plot 4 line charts with one column. The grobs look OK when saving the file as a .png or .pdf, if the dimensions are large. However, when I shrink the height of the plot, the top grob gets compressed.
How can I prevent grid.arrange from compressing grobs?
Some ugly code:
(a<-autoplot(mars.prcp1yrs) + labs(y="", x="") +theme_light()+ylim(60,210)+
theme(text=element_text(size=8),
axis.text.y=element_text(size=8),axis.text.x=element_blank(),
axis.title.y=element_blank(),
axis.ticks.x=element_blank(),
plot.margin=unit(c(0.1,0.1,0.1,0.1),"in")))
(b<-autoplot(jupiter.prcp1yrs) + labs(y="",x="")+ theme_light()+ylim(60,210)+
theme(text=element_text(size=8),axis.text.y=element_text(size=8),
axis.text.x=element_blank(),axis.title.y=element_blank(),
axis.ticks.x=element_blank(),plot.margin=unit(c(-0.3,0.1,0.1,0.1),"in")))
(c<-autoplot(saturn.prcp1yrs) +labs(y="",x="") + theme_light()+ylim(60,210)+
theme(text=element_text(size=8),
axis.text=element_text(size=8),
axis.text.x=element_blank(),axis.title.y=element_blank(),
axis.ticks.x=element_blank(),plot.margin=unit(c(-0.3,0.1,0.1,0.1),"in")))
(d<-autoplot(earth.prcp1yrs) +labs(y="",x="") +theme_light()+ylim(60,210)+
theme(text=element_text(size=8),axis.text=element_text(size=8),
axis.ticks.x=element_blank(),axis.title.y=element_blank(),
plot.margin=unit(c(-0.3,0.1,0.1,0.1),"in")))
prcp.grid<-grid.arrange(a,b,c,d, ncol=1)
png("plot.png",width=3740,height=1000,res=500)
old.par <- par(mfrow=c(2, 2))
grid.arrange(prcp.grid, ncol=2)
par(old.par)
dev.off()
Here is the output
(I used this aspect ratio just to dramatize compression of the top grob.):