R: Resize 2 x 2 plot output

1.1k views Asked by At

I have 4 maps to plot and would like to plot them in a single plot area so I use the code

par(mfrow=c(2,2), bty="n")

However, the result is lots of useless blank space around my maps (which become also too small).

The image below shows how much space is taken up by each map (blue rectangle) relative to the plot area.

Representation of plot area outputs

Is it possible to go from the current situation (cf. 2 x 2 plot fit) to the desired situation (cf. Desired better fit)?

I tried changing width and height parameters (dev.new(width=x, height=y)) but with no luck.

1

There are 1 answers

0
Tad Dallas On BEST ANSWER

I would suggest using the layout function, though using par is fine too. I give a simple example below, in which you can adjust par(mar=c()) settings for each individual plot, bringing them closer together. layout allows you to adjust relative heights of plots with the height parameter, which might be useful when trying to get panel plots to be all the same height, when you have the x-axis only for the lower tier plots.

y=runif(100)
x=runif(100)

layout(matrix(c(1,2,3,4), byrow=TRUE, ncol=2,nrow=2))
par(mar=c(3,3,0.5,0.5))
plot(y,x, xaxt='n')

par(mar=c(3,3,0.5,0.5))
plot(y,x, xaxt='n')

par(mar=c(3,3,0.5,0.5))
plot(y,x)

par(mar=c(3,3,0.5,0.5))
plot(y,x, yaxt='n')