seapen
seapen

Reputation: 394

R, plot , font size changes in multiple plot figures

I am creating graphs for a publication and would like them to have the same font size.

When I create a figure with multiple plots, the font size decreases even though I haven't changed the tiff() resolution or pointsize parameter. I increased the figure size according to ultimately fit the number of plots, and made sure the margins are equivalent for single and multiple plot figures.

Following is an example code (The font size is consistent between 1x1 and 2x1 figure, but decreases for 3x2 figure):

tiff("1x1.tif", width=3,height=2.5,units="in",res=600,pointsize=8,
compression="lzw",restoreConsole=T)
par(mfrow=c(1,1),mar=c(4,4,.5,.5)+0.1)
plot(x=rnorm(10),y=rnorm(10))
dev.off()

tiff("2x1.tif", height=2.5*2,width=3,units="in",res=600,pointsize=8,
compression="lzw",restoreConsole=T)
par(mfrow=c(2,1),mar=c(2,4,2.5,0.5)+0.1)
plot(x=rnorm(10),y=rnorm(10),xaxt="n",xlab="")
par(mar=c(4,4,0.5,0.5)+0.1)
plot(x=rnorm(10),y=rnorm(10))
dev.off()

tiff("3x2.tif", height=2.5*3,width=3*2,units="in",res=600,pointsize=8,
compression="lzw",restoreConsole=T)
par(mfrow=c(3,2),mar=c(.5,4,4,0.5)+0.1)
plot(x=rnorm(10),y=rnorm(10),xaxt="n",xlab="")
par(mar=c(.5,2,4,2.5)+0.1)
plot(x=rnorm(10),y=rnorm(10),xaxt="n",xlab="",yaxt="n",ylab="")
par(mar=c(2.5,4,2,0.5)+0.1)
plot(x=rnorm(10),y=rnorm(10),xaxt="n",xlab="")
par(mar=c(2.5,2,2,2.5)+0.1)
plot(x=rnorm(10),y=rnorm(10),xaxt="n",xlab="",yaxt="n",ylab="")
par(mar=c(4.5,4,0,0.5)+0.1)
plot(x=rnorm(10),y=rnorm(10))
par(mar=c(4.5,2,0,2.5)+0.1)
plot(x=rnorm(10),y=rnorm(10),yaxt="n",ylab="")
dev.off()

Why is this happening?

P.S.: I'm not using ggplot2 or lattice because I'm using my own error bar function on the "actual" figures (I can't remember why right now but I tried working with the ggplot2 error bars and didn't get what I wanted).

Upvotes: 2

Views: 7706

Answers (1)

Backlin
Backlin

Reputation: 14872

The parameter controlling the overall relative size of objects in the plot (including text) is called cex. When you use many panels it is decreased by default, but it can be overridden by manually setting it to 1.

par(mfrow=c(3,2), mar=c(.5,4,4,0.5)+0.1, cex=1)

Off-topic-tip

It looks like you should use oma (outer margin) rather than calling par(mar=...) between the calls to plot. I find it very useful, but hardly anyone seems to know of it. Also ann=FALSE turns off all anotations, las=1 turns axis tick labels horizontal.

par(mfrow=c(3,2), oma=c(4.5, 4, 4, 2.5), mar=rep(.1, 4), cex=1, las=1)
plot(x=rnorm(10), y=rnorm(10), ann=FALSE, xaxt="n")
plot(x=rnorm(10), y=rnorm(10), ann=FALSE, xaxt="n", yaxt="n")
plot(x=rnorm(10), y=rnorm(10), ann=FALSE, xaxt="n")
plot(x=rnorm(10), y=rnorm(10), ann=FALSE, xaxt="n", yaxt="n")
plot(x=rnorm(10), y=rnorm(10), ann=FALSE)
plot(x=rnorm(10), y=rnorm(10), ann=FALSE, yaxt="n")
title("My plot", outer=TRUE)
mtext("X-axis label", 1, 3, outer=TRUE)
mtext("Y-axis label", 2, 3, outer=TRUE, las=0)

enter image description here

Upvotes: 10

Related Questions