Search code examples
rgraphicsscatter-plotsmoothing

How to reduce the empty space between the columns of a multiple plot layout?


There is a lot of empty space between two plots of the same row. I tried to rectify this by changing the outer margins and plot margins using par() but it isn't working. Another solution I thought of was to increase the size of individual plots but I don't know how to.

layout(matrix(1:8, ncol=2, byrow=TRUE))
par(oma=c(5,0.1,1,1), mar=c(5,0.1,1,1),  pty="s")

plot(Annual.Rainfall.in.mm ~ Year, data=AnnRF, ylab = "Rainfall (mm)", sub="(a)", col="blue", bg="blue", pch=21, cex.lab = 1.4)
lines(lowess(AnnRF$Year, AnnRF$Annual.Rainfall.in.mm), col="red", lwd=3)

plot(Annual.Rainy.Days ~ Year, data=AnnRD, ylab = "Rainy Days", sub="(b)", col="blue", bg="blue", pch=21, cex.lab = 1.4)
lines(lowess(AnnRD$Year, AnnRD$`Annual.Rainy.Days`), col="red", lwd=3)

plot(Monsoon.Rainfall.in.mm ~ Year, data=MonRF, ylab = "Rainfall (mm)", sub="(c)", col="blue", bg="blue", pch=21, cex.lab = 1.4)
lines(lowess(MonRF$Year, MonRF$`Monsoon.Rainfall.in.mm`), col="red", lwd=3)

plot(Monsoon.Rainy.Days ~ Year, data=MonRD, ylab = "Rainy Days", sub="(d)", col="blue", bg="blue", pch=21, cex.lab = 1.4)
lines(lowess(MonRD$Year, MonRD$`Monsoon.Rainy.Days`), col="red", lwd=3)

plot(Pre.Monsoon.Rainfall.in.mm ~ Year, data=PreRF, ylab = "Rainfall (mm)", sub="(e)", col="blue", bg="blue", pch=21, cex.lab = 1.4)
lines(lowess(PreRF$Year, PreRF$`Pre.Monsoon.Rainfall.in.mm`), col="red", lwd=3) 

plot(Pre.Monsoon.Rainy.Days ~ Year, data=PreRD, ylab = "Rainy Days", sub="(f)", col="blue", bg="blue", pch=21, cex.lab = 1.4)
lines(lowess(PreRD$Year, PreRD$`Pre.Monsoon.Rainy.Days`), col="red", lwd=3)

plot(Post.Monsoon.Rainfall.in.mm ~ Year, data=PostRF, ylab = "Rainfall (mm)", sub="(g)", col="blue", bg="blue", pch=21, cex.lab = 1.4)
lines(lowess(PostRF$Year, PostRF$`Post.Monsoon.Rainfall.in.mm`), col="red", lwd=3)

plot(Post.Monsoon.Rainy.Days ~ Year, data=PostRD, ylab = "Rainy Days", sub="(h)", col="blue", bg="blue", pch=21, cex.lab = 1.4)
lines(lowess(PostRD$Year, PostRD$`Post.Monsoon.Rainy.Days`), col="red", lwd=3)

Rplot


Solution

  • You can save the plot by controlling with overall width and height of the image i.e. plot page size, for example, as a png file.

    The argument pty = "s" forces a square plot. So by playing around with the width and height arguments of the plot page size you can get the appearance you want.

    Alternatively you can use the respect argument of layout and use cex.lab to vary the axis label size.

    layout(matrix(1:8, ncol=2, byrow=TRUE), respect = TRUE)
    
    par(oma=c(0, 0, 0, 0), 
        mar=c(5,4,1,1),  
        pty="s")
    
    for(i in 1:8) plot(iris$Sepal.Length, iris$Petal.Length, sub = i,
                       cex.lab = 1.5)
    

    enter image description here