简体   繁体   English

mtext y轴标签,涵盖两个瓦片图

[英]mtext y-axis label that covers a two-tile plot

How do I use mtext(side = 2,text="y-axis") to place a y-axis label for both tiles in the example below? 在下面的示例中mtext(side = 2,text="y-axis")如何使用mtext(side = 2,text="y-axis")为两个图块放置y轴标签? That is, instead of placing two separate y-axis labels, I want to be able to place a single label. 也就是说,我希望能够放置一个标签,而不是放置两个单独的y轴标签。

layout(matrix(1:2,ncol=1),widths=1,heights=c(2,2),respect=FALSE)
par(mar = c(0, 4.1, 4.1, 2.1))
plot(rnorm(100),main="Hi",type='l',ylab='',xaxt='n')
par(mar = c(4.1, 4.1, 0, 2.1))
plot(rnorm(100),main="",xlab="Hi",type='l',ylab='')

The correct way to do it is to add an outer margin with par(oma=...) , suppress annotations with ann=FALSE , then add them manually in the outer margin with mtext(..., outer=TRUE) etc. 正确的方法是使用par(oma=...)添加外边距 ,使用ann=FALSE抑制注释,然后使用mtext(..., outer=TRUE)在外边距中手动添加它们。

layout(matrix(1:2,ncol=1),widths=1,heights=c(2,2),respect=FALSE)
par(mar = rep(0, 4), oma=c(4, 4, 4, 2), las=1)
plot(rnorm(100), type='l', ann=FALSE, xaxt='n')
plot(rnorm(100), type='l', ann=FALSE)

title("Hi", outer=TRUE)
mtext("x-axis", 1, 3, outer=TRUE)
mtext("y-axis", 2, 3, outer=TRUE, las=0)

Here's a reference: http://research.stowers-institute.org/efg/R/Graphics/Basics/mar-oma/ 这是一个参考: http//research.stowers-institute.org/efg/R/Graphics/Basics/mar-oma/

Also notice the las argument that turns all labels horizontal. 还要注意使所有标签水平的las参数。 It maks it easier to read and shows your audience you know your plotting :) 它让它更容易阅读并向您的观众展示您知道的情节:)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM