How to use a common axis for three identical time and value graphs

I have three timestamped series of measurements taken at the same interval, but with different actual timestamps. I would like to show these three trajectories in a combined plot, but since in each case the x axis (timestamps) is different, I have some problems. Is there a way to do this without selecting the x axis to use and interpolate the y values ​​for the other two series of measurements? I am new to R, but I feel that there is something obvious that I am missing.

For instance:

Episode 1

Time    Value
1.023   5.786
2.564   10.675
3.678   14.678
5.023   17.456

Series 2

0.787   1.765
1.567   3.456
3.011   5.879
4.598   7.768

Series 3

1.208   3.780
2.478   6.890
3.823   9.091
5.125   12.769
+3
source share
4 answers

With basic graphics, you can use a combination of plotand pointsor 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"))

?legend, . , ggplot2 :

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

qplot(Time, value, data = plotdata, colour = L1)
+5

:

t1 <- "Time Value
1.023   5.786
2.564   10.675
3.678   14.678
5.023   17.456"

t2 <- "Time Value
0.787   1.765
1.567   3.456
3.011   5.879
4.598   7.768"

t3 <- "Time Value
1.208   3.780
2.478   6.890
3.823   9.091
5.125   12.769"

tex1 <- read.table(textConnection(t1), header = TRUE)
tex2 <- read.table(textConnection(t2), header = TRUE)
tex3 <- read.table(textConnection(t3), header = TRUE)

plot(tex1, type="l", xlim=range(tex1$Time, tex2$Time, tex3$Time), ylim=range(tex1$Value, tex2$Value, tex3$Value), main="Common Time Axis for 3 Data Series", col="black")
grid()
lines(tex2, col="red")
lines(tex3, col="blue")

enter image description here

+3

- , , : points xlim.
( ) plot, xlim, .
points lines, , , , color , .
, !

+1

Subtract the minimum time for each run. Define a maximum of three results as xlim [2]. Plot using a label suppression matnet, and then add your tags = and at = with the axis ().

0
source

All Articles