您可以通過?axis
或?Axis
來繪製座標軸。要將座標軸跨越多個座標圖,必須重置座標系usr。
請在下面找到一個基地的圖形解決方案:
## store number of rows
nRow <- 10
## your example code
## (only the number "10" is replaced by nRow and oma is adapted)
plot.new()
par(mar=c(2, 2, 1, 1), oma=c(2, 4, 0, 4), xpd=NA)
for (i in 1:nRow) {
par(mar=c(2, 2, 1, 1), fig=c(0, 0.5, (nRow-i)/nRow, ((nRow+1)-i)/nRow), new=TRUE)
matplot(rnorm(20)*sample(100, 1),
col="blue", axes=F, type="l", lwd=10, xlab="", ylab="")
par(mar=c(2, 2, 1, 1), fig=c(0.5, 1, (nRow-i)/nRow, ((nRow+1)-i)/nRow), new=TRUE)
matplot(rnorm(20)*sample(100, 1),
col="red", axes=F, type="l", lwd=10, xlab="", ylab="")
}
## define new user coordinates
usr <- c(0, 1, 0, 1) ## x1, x2, y1, y2
## calculate tick positons
## in general: (usr[3]+(diff(usr[3:4])/(nRow-1))*0:(nRow-1))
## but our usecase is much easier:
ticksAt <- 1/(nRow-1)*0:(nRow-1)
## choose left column and reset user plotting area (usr)
par(mar=c(2, 2, 1, 1), fig=c(0, 0.5, 0, 1), usr=usr, new=TRUE)
## draw axis; see ?Axis for details
Axis(side=2, at=ticksAt, labels=as.character(1:(nRow)), line=0.5)
## choose right column and reset user plotting area (usr, not needed because already done)
par(mar=c(2, 2, 1, 1), fig=c(0.5, 1, 0, 1), usr=usr, new=TRUE)
## draw axis; see ?Axis for details
Axis(side=4, at=ticksAt, labels=as.character((nRow+1):(2*nRow)), line=0.5)
你怎麼想的刻度標記看?例如,從您的代碼派生的示例圖有2列圖。是第二列情節的勾號標籤是第一列的刻度標籤的延續嗎?例如,如果第一列的刻度標籤是1,2,3,4,5,您是否希望第二列的刻度標籤爲6,7,8,9,10,或者您是否想要1,2,3,4 ,再次5。 – Alex
@ X.He前者,即一列1到5,第二列6到10繼續 – user1202664