【发布时间】:2019-06-04 20:24:45
【问题描述】:
我想使用双 y 轴绘制 4 组数据点的图。前两个在左侧 y 轴上,后两个在右侧 y 轴上。前两个属于从 5000 到 50,000 的一组数字。第二组数据属于1-100的范围。我想绘制它以便很容易辨别这两个轴不仅在不同的比例上,而且来自两个不同范围的不同集合的点之间的高度显然很大。我不希望能够绘制一条水平线,这表明左侧 y 轴上的某个数字可以双射映射到右侧 y 轴上的某个数字。我想让它使得通过左 y 轴和右 y 轴的任何点的水平线仅属于与左轴或右轴相关的一组。
How can I plot with 2 different y-axes?。有
我会使用 twoord.plot 从 plotrix v3.7-5 由 Jim Lemon 撰写,但这比 base R 有缺点,因为我不能将 4 组数据添加到一个图中。我只能使用 2 组 (x,y) 对和 2--ord 图。我理论上可以使用基数 R 绘制 n 组 (x,y) 对。
无
以下是不起作用的:
time <- seq(0,72,12)
betagal.abs <- c(0.05,0.18,0.25,0.31,0.32,0.34,0.35)
cell.density <- c(0,1000,2000,3000,4000,5000,6000)
## add extra space to right margin of plot within frame
par(mar=c(5, 4, 4, 6) + 0.1)
## Plot first set of data and draw its axis
plot(time, betagal.abs, pch=16, axes=FALSE, ylim=c(0,1), xlab="", ylab="",
type="b",col="black", main="Mike's test data")
axis(2, ylim=c(0,1),col="black",las=1) ## las=1 makes horizontal labels
mtext("Beta Gal Absorbance",side=2,line=2.5)
box()
## Allow a second plot on the same graph
par(new=TRUE)
## Plot the second plot and put axis scale on right
plot(time, cell.density, pch=15, xlab="", ylab="", ylim=c(0,7000),
axes=FALSE, type="b", col="red")
## a little farther out (line=4) to make room for labels
mtext("Cell Density",side=4,col="red",line=4)
axis(4, ylim=c(0,7000), col="red",col.axis="red",las=1)
## Draw the time axis
axis(1,pretty(range(time),10))
mtext("Time (Hours)",side=1,col="black",line=2.5)
## Add Legend
legend("topleft",legend=c("Beta Gal","Cell Density"),
text.col=c("black","red"),pch=c(16,15),col=c("black","red"))
【问题讨论】: