R在两个不同的比例尺上绘制线条

时间:2018-12-12 09:18:00

标签: r

我已经在一个图中建立了两个图形(两个不同的y轴,但在同一图形上绘制)。我想显示左侧的值和右侧的值之间的联系(它们是否始终保持> 0或<0或变化?)

现在,我需要用一条线链接图形的两侧,以查看其是否减少/增加。因此,我希望左侧的相应点通过一条线链接到右侧的相应点。

但是因为左右两边的y轴值不同,所以我没有弄清楚这是如何工作的。 这是我建立图表的代码:

## Plot first set of data and draw its axis
plot(rep(1, length(DEG)), DEG, xlim = c(0,4), xaxt = "n",
    ylim = c(-5, 5), col = "black", xlab = "", ylab = "")
axis(1, at = c(1))

## Allow a second plot on the same graph
par(new = TRUE)

## Plot the second plot and put axis scale on right
plot(rep(3, length(DMG)), DMG, axes = F, xlim = c(0, 4), xaxt = "n", 
    ylim = c(-80, 80), col = "black", xlab = "", ylab = "")
axis(1, at = c(3)))
axis(side = 4)
abline(h = 0, col = "red")

有人有想法吗?我尝试了基本路线:

lines(x$DEG[x$Genes == "FEX_0000936"], x$DMG[x$Genes == "FEX_0000936"],
    type="o", pch=22, col="seagreen3")

这是我的图表,也许看起来更清晰:

感谢您的帮助。

0 个答案:

没有答案