Skip to content
Prev 5364 / 7420 Next

Fixing vertical and horizontal axes in R

Hi Margaret,

Here is an example of scaling your figure based on the extension of the
axes. The margins are added as additional space beyond that scaling (here
in inches with par(mai=...) ). Having the additional argument asp=1 will
maintain the same aspect ration for both axes:

DIMS <- dim(volcano)
DIMS
fig.width <- 6
fig.height <- fig.width * (DIMS[2]/DIMS[1])
fig.height
MAI <- c(1,1,0.1,0.1) # margins in inches
fig.width <- fig.width + sum(OMI[c(2,4)]) # final figure width
fig.height <- fig.height + sum(OMI[c(1,3)]) # final figure height

jpeg("volcano.jpeg", width = fig.width, height = fig.height, units="in",
res=400)
op <- par(mai=MAI)
image(x=seq(nrow(volcano)), y=seq(ncol(volcano)), z=volcano, asp=1)
abline(v=seq(0, nrow(volcano), by=5), col=8, lty=3, lwd=0.75)
abline(h=seq(0, ncol(volcano), by=5), col=8, lty=3, lwd=0.75)
par(op)
dev.off()

Cheers,
Marc

On Thu, May 12, 2016 at 8:51 AM, Shane Baylis <shane.m.baylis at gmail.com>
wrote: