覆盖两图块的多行文字y轴标签 [英] mtext y-axis label that covers a two-tile plot

查看:122
本文介绍了覆盖两图块的多行文字y轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的示例中,如何使用mtext(side = 2,text="y-axis")为两个图块放置y轴标签?也就是说,我希望能够放置一个标签,而不是放置两个单独的y轴标签.

How do I use mtext(side = 2,text="y-axis") to place a y-axis label for both tiles in the example below? That is, instead of placing two separate y-axis labels, I want to be able to place a single label.

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='')

推荐答案

正确的方法是用par(oma=...)添加外边距,用ann=FALSE取消注释,然后添加可以使用mtext(..., outer=TRUE)等在外侧边缘手动将其放置.

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.

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)

这里是参考: http://research.stowers -institute.org/efg/R/Graphics/Basics/mar-oma/

还要注意las参数,该参数将所有标签变为水平.它使它更易于阅读,并向听众展示您知道您的情节:)

Also notice the las argument that turns all labels horizontal. It maks it easier to read and shows your audience you know your plotting :)

这篇关于覆盖两图块的多行文字y轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆