【问题标题】:mtext: smaller labels description when layout is usedmtext:使用布局时较小的标签描述
【发布时间】:2014-09-22 09:27:42
【问题描述】:

使用 mtext 作为标签描述与使用 xlab 有不同的作用。如何使 mtext 标签的大小始终与使用 xlab 时的大小相同(而不总是定义 cex 参数)。在下面的最小示例中 cex=cex.lab=1 两个数字。但是大小不同。

layout(matrix(c(1,1,2,2), ncol=1))
op<-par(mar=c(4,4,2,1))
plot(1:10, xlab="", ylab="", main="This is my title")
mtext("this is the x-axis", side=1, line=2.75, cex=1)
mtext("this is the y-axis", side=2, line=2.5, cex=1)
plot(1:10,  xlab="this is smaller", ylab="this is smaller", main="This is my title", cex.lab=1)
par(op)

【问题讨论】:

  • 为什么不对两个图都使用xlabmtext
  • 或者使用title(xlab="this is the x-axis", ylab="this is the y-axis")而不是mtext

标签: r plot labels axis-labels par


【解决方案1】:

当使用布局时,plot 中的cex=1 的含义是不同的,但我没想到这种差异会扩展到 mtext,因为它的活动在各个绘图区域之外。您可以通过反转 2/3 的预期因子来反转 plot 内“有效”-cex 的默认减少:

layout(matrix(c(1,1,2,2), ncol=1))
op<-par(mar=c(4,4,2,1))
plot(1:10, xlab="", ylab="", main="This is my title")
mtext("this is the x-axis", side=1, line=2.75, cex=1)
mtext("this is the y-axis", side=2, line=2.5, cex=1)
plot(1:10,  xlab="this is _not_ smaller", 
            ylab="this is _not_ smaller, either", 
            main="This is my title", 
            cex.lab=3/2)
par(op)

进一步阅读:

 ?par  # scroll down to mfcol, mfrow

【讨论】:

  • 终于把这个问题追下来了,非常令人沮丧,尤其是当你在调试模式下查询cex时它总是显示1。无论如何,根据mfrowcex.lab=3/2如果有的话应该是cex.lab=1/0.83如您的示例中的 2 行,cex.lab=1/0.66 用于三行或更多行。或更完整地说,cex.lab = par('cex.lab') * 1/0.66
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-07
  • 1970-01-01
  • 1970-01-01
  • 2015-03-13
相关资源
最近更新 更多