I’m trying to plot two time series into the same graph in R.
My data is as follows:
Series 1:
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
And series 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
The code that I have is:
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")
I would like to plot these two series chronologically with the same x axis for both with the same scale, I mean in one unique chronological x axis.
How might I best accomplish this in R?
Thanks in advance.
You need to define before the limit of the range for x and y in your plot and you need to have the same limit for each plot.