[R] R: layout() affects margin size in subfigures [unexpected behaviour]
Malcolm Perry
mgperry32 at gmail.com
Thu Jan 14 14:42:10 CET 2016
The absolute margin size of figures in R seems to be affected by the layout
of the plot, which i think is surprising (not sure if it qualifies as a
bug). The following plots have different margins sizes, with the 1x3 plot
margins being smaller (thus giving a larger plot area). This is causing
havoc with a package I am writing to automatically generate composite
figures, since labels are positioned differently depending on the number of
panels.
plot_box <- function() {
plot(1, 1, type='n', bty='n', xaxt='n', yaxt='n', xlab='', ylab='')
box(lwd = 6)
box("figure", lwd=6, col='red')
}
png("margin_test_1.png", width=1000, height=500)
par(oma=c(0,0,0,0))
layout(t(1:2))
par(mar=c(3, 3, 3, 3))
plot_box()
par(mar=c(3, 3, 3, 3))
plot_box()
dev.off()
png("margin_test_2.png", width=1500, height=500)
par(oma=c(0,0,0,0))
layout(t(1:3))
par(mar=c(3, 3, 3, 3))
plot_box()
par(mar=c(3, 3, 3, 3))
plot_box()
par(mar=c(3, 3, 3, 3))
plot_box()
dev.off()
I have also posted this question to StackOverflow, and it has images of the
graphical output which illustrate the problem better:
http://stackoverflow.com/questions/34790682/r-layout-affects-margin-size-in-plot-regions
Thanks,
Malcolm
PS I was unsure if this question belonged to help or devel - I will repost
on devel if it is likely to get better answers.
[[alternative HTML version deleted]]
More information about the R-help
mailing list