Difference between par(fig=c()) , par(mfrow=), par(mfcol=c()), and layout() to plot several plots in the same page

There are several mechanisms that can be used to plot several plots in the same page. You can use mfrow(), par(fig=c()) or layout().
Trying the 3 different methods, a big difference has been noted that is not clearly stated in the documentation. layout() function and par(mfrow=) changes the par("cex") whereas par(fig=c()) does not change it. In the documentation of par:
In a layout with exactly two rows and columns the base value of "cex" is reduced by a factor of 0.83: if there are three or more of either rows or columns, the reduction factor is 0.66.

The change or not of par("cex") is important if mtext() is used because it does not used by default the par("cex") parameter. It must be forced to use it.


Note that the size of characters is setup to par(cex=0.83):

# the order is by row
dev.off()
plot.new()
par("cex")
par(mfrow=c(2, 2))
par("cex")
plot(1, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
plot(2, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
plot(3, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
plot(4, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))

# the order is by column
dev.off()
plot.new()
par("cex")
par(mfcol=c(2, 2))
par("cex")
plot(1, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
plot(2, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
plot(3, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
plot(4, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))

dev.off()
plot.new()
par("cex")
layout(mat=matrix(1:4, ncol=2))
par("cex")
plot(1, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
plot(2, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
plot(3, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
plot(4, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))



Note that the size of characters is setup to par(cex=1):

dev.off()
plot.new()
par("cex")
par(fig=c(0, 0.5, 0, 0.5))
par("cex")
plot(1, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
par(fig=c(0, 0.5, 0.5, 1), new=TRUE)
plot(2, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
par(fig=c(0.5, 1, 0, 0.5), new=TRUE)
plot(3, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))
par(fig=c(0.5, 1, 0.5, 1), new=TRUE)
plot(4, bty="n")
mtext(side=4, text="Essai", cex=par("cex"))





Commentaires

Posts les plus consultés de ce blog

Standard error from Hessian Matrix... what can be done when problem occurs

stepAIC from package MASS with AICc

Install treemix in ubuntu 20.04