2

我正在为出版物创建图表,并希望它们具有相同的字体大小。

当我创建具有多个 plots的图形时,即使我没有更改分辨率或参数,字体大小也会减小。我根据最终适合的地块数量增加了图形大小,并确保单个和多个地块图形的边距相等。tiff()pointsize

下面是一个示例代码(字体大小在 1x1 和 2x1 图形之间是一致的,但对于 3x2 图形会减小):

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()

为什么会这样?

PS:我没有使用ggplot2或者lattice因为我在“实际”数字上使用了我自己的错误栏功能(我现在不记得为什么但我尝试使用 ggplot2 错误栏并没有得到我想要的)。

4

1 回答 1

10

控制绘图中对象(包括文本)的整体相对大小的参数称为cex。当您使用许多面板时,默认情况下它会减小,但可以通过手动将其设置为 来覆盖它1

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

题外话

看起来您应该使用oma(outer margin) 而不是在调用par(mar=...)之间调用plot. 我觉得它非常有用,但似乎几乎没有人知道它。同时ann=FALSE关闭所有注释,las=1将轴刻度标签水平旋转。

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)

在此处输入图像描述

于 2012-09-21T16:20:34.690 回答