如何在三个相似的时间/值图表中使用公共轴

Wil*_*unn 3 plot axis r measurement time-series

我有三个带时间戳的测量系列,采用相同的间隔,但具有不同的实际时间戳.我想在组合图中显示这三个轨迹,但由于x轴(时间戳)在每种情况下都不同,我遇到了一些麻烦.有没有办法在不选择x轴的情况下使用和插值其他两个测量序列的y值?我对R很陌生,但我觉得我有一些明显的东西可以忽略.

例如:

系列1

Time    Value
1.023   5.786
2.564   10.675
3.678   14.678
5.023   17.456
Run Code Online (Sandbox Code Playgroud)

系列2

0.787   1.765
1.567   3.456
3.011   5.879
4.598   7.768
Run Code Online (Sandbox Code Playgroud)

系列3

1.208   3.780
2.478   6.890
3.823   9.091
5.125   12.769
Run Code Online (Sandbox Code Playgroud)

Cha*_*ase 5

使用基本图形,您可以使用plotpoints或的组合lines:

dat1 <- data.frame(Time = c(1.023, 2.564, 3.678, 5.023), Value = c(5.786, 10.675, 14.678, 17.456))
dat2 <- data.frame(Time = c(0.787, 1.567, 3.011, 4.598), Value = c(1.765, 3.456, 5.879, 7.768))
dat3 <- data.frame(Time = c(1.208, 2.478, 3.823, 5.125), Value = c(3.780, 6.890, 9.091, 12.769))

with(dat1, plot(Time, Value, xlim = c(0,6), ylim = c(0,20)))
with(dat2, points(Time, Value, col = "red"))
with(dat3, points(Time, Value, col = "green"))
Run Code Online (Sandbox Code Playgroud)

看看?legend添加一个传奇.或者,学习ggplot2并让它为您处理它的一部分:

library(ggplot2)
library(reshape)
plotdata <- melt(list(dat1 = dat1, dat2 = dat2, dat3 = dat3), "Time")

qplot(Time, value, data = plotdata, colour = L1)
Run Code Online (Sandbox Code Playgroud)