2013-10-17 43 views
2

如何在下面的示例中使用mtext(side = 2,text="y-axis")爲兩個瓷磚放置y軸標籤?也就是說,我不想放置兩個獨立的y軸標籤,而是希望能夠放置一個標籤。多行文字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='') 

回答

7

做正確的方法是添加一個外緣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) 

手動添加他們這裏有一個參考:http://research.stowers-institute.org/efg/R/Graphics/Basics/mar-oma/

另請注意,las參數將所有標籤水平。它使得它更容易閱讀並向觀衆展示你知道你的陰謀:)

enter image description here