我正在尝试将两个时间序列绘制到 R 中的同一个图中。
我的数据如下:
系列一:
dates values
1 2012-09-01 12:00:00 33.6
2 2012-09-05 13:00:00 32.0
3 2012-09-06 15:30:00 30.0
4 2012-09-07 12:45:00 30.0
5 2012-09-08 21:15:00 30.0
6 2012-09-11 15:00:00 28.4
系列2:
dates values
1 2012-09-03 14:05:00 15.6
2 2012-09-05 08:00:00 23.0
3 2012-09-09 15:55:00 19.0
4 2012-09-11 23:00:00 22.0
5 2012-09-14 02:40:00 34.0
6 2012-09-15 12:09:00 29.4
我拥有的代码是:
var1<-var1[,c("Sampling_Time","Value")]
var2<-var2[,c("Sampling_Time","Value")]
var1$Sampling_Time<- as.POSIXct(var1$Sampling_Time, format="%Y-%m-%d %H:%M:%S")
var2$Sampling_Time<- as.POSIXct(var2$Sampling_Time, format="%Y-%m-%d %H:%M:%S")
plot(var1$Sampling_Time, var1$Value, type= "p" , xlim= NULL, col = "red", size =1,
xlab= "Time",ylab= "Value", main= "Graphic",format="%Y-%b-%d")
par(new=TRUE)
plot(var2$Sampling_Time, var2$Value, type= "p" , xlim= NULL, col = "blue", size =1,
xlab= "Time",ylab= "Value", main= "Graphic",format="%Y-%b-%d")
我想用相同的 x 轴按时间顺序绘制这两个系列,它们的比例相同,我的意思是在一个独特的按时间顺序排列的 x 轴上。
我怎样才能最好地在 R 中实现这一点?
提前致谢。