问题
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='')
回答1:
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)
Here's a reference: http://research.stowers-institute.org/efg/R/Graphics/Basics/mar-oma/
Also notice the las
argument that turns all labels horizontal. It maks it easier to read and shows your audience you know your plotting :)

来源:https://stackoverflow.com/questions/19422625/mtext-y-axis-label-that-covers-a-two-tile-plot