2
我想就用,R 4軸的陰謀,以便它類似於這樣的情節:如何使用R製作以下圖形?
我已經看過了Quick-R website徵求意見和修改自己的例子之一(稱爲A Silly Axis Example
):
# specify the data
x <- c(1:5); y <- x/2;
w <- c(2:4)
z <- c(1:5)
# create extra margin room on the right for an axis
par(mar=c(5, 4, 4, 8) + 0.1)
# plot x vs. y
plot(x, y,type="b", pch=21, col="red",
yaxt="n", lty=3, xlab="", ylab="")
# add x vs. 1/x
lines(x, z, type="b", pch=22, col="blue", lty=2)
# draw an axis on the left
axis(2, at=x,labels=x, col.axis="red", las=2)
# draw an axis on the right, with smaller text and ticks
axis(4, at=w,labels=round(w,digits=2),
col.axis="blue", las=2, cex.axis=0.7, tck=-.01)
# draw an axis on the top
axis(3, at=z,labels=round(z,digits=2),
col.axis="blue", las=2, cex.axis=0.7, tck=-.01)
# add a title for the right axis
mtext("L", side=3, line=3, cex.lab=1,las=2, col="blue")
# add a title for the right axis
mtext("OSR", side=4, line=3, cex.lab=1,las=2, col="red")
# add a main title and bottom and left axis labels
title("", xlab="GSI", ylab="FSI")
此代碼產生以下情節:
我有DIF很難弄清楚不同的軸可以具有不同的尺度。例如,我希望頂軸L
從5到13,但如果我設置了z <-c(5:13)
,它不會將軸設置爲這些值。不過,我可以覆蓋哪些標籤:
axis(3, at=z,labels=round(c(9:13),digits=2), col.axis="blue",
las=2, cex.axis=0.7, tck=-.01)
但當時如果我想用繪製這四個參數的一個點,點不會出現在正確的位置顯示出來。我應該怎麼做?
感謝您的回答Joran;它運作良好。只需要澄清一下,我可以使用次軸繪製一個點,並且會認爲這些軸的刻度線間距? – djq