Я хотел бы сделать график с 4 осями в R, чтобы он выглядел аналогично этому графику:
![enter image description here](https://i.stack.imgur.com/KOZJC.png)
Я заглянул на сайт Quick-R за советом и изменил один из их примеров (названный 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")
Этот код создает следующий график:
![enter image description here](https://i.stack.imgur.com/eNw66.png)
Мне трудно понять, как разные оси могут иметь разные масштабы. Например, я хочу, чтобы верхняя ось 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)
но тогда, если я захочу построить точку с этими четырьмя параметрами, точка не будет отображаться в правильном месте. Как мне это сделать?