0
votes

I have a time series like this which consists of past 4 months (Feb, Mar, Apr, May) data:

         "timestamp" "rain_intensity"
  "1" "2012-06-15 01:05:00 UTC" 2.6
  "2" "2012-06-15 01:00:00 UTC" 9.6
  "3" "2012-06-15 00:55:00 UTC" 18.5
  "4" "2012-06-15 00:50:00 UTC" 25.7
  "5" "2012-06-15 00:45:00 UTC" 32.8
  "6" "2012-06-15 00:40:00 UTC" 38.7

And I have a similar kind of one more time series, but which consists of past 2 months (Apr, May) data. I have to plot them on the same plot one above the x axis(4months data) and one below (2months data) the x axis. 2nd plot.

Using mfrow in par was unsuccessful since the x axes are not same.

How can I go for it?

2
You can first plot 4 months data and then plot with add = TRUE for the 2 months. You could also use ggplot2 and use faceting.Roman Luštrik

2 Answers

1
votes

Defining parameter xlim in the plot function might help.

0
votes

ggplot2 provides a very elegant way to express this. Here's a code snippet for Roman's answer.

First, get the data into a convenient format, all in the same data.frame. I will assume it looks like this

timestamp variable        value
[..]      rain_intensity1 2.6     # from the table you show above
[..]      rain_intensity2 5.4     # from the other table you mention

melt from package reshape helps to do this transformation. Now the plot

qplot(timestamp, value, data=my_table, facets= .~variable)

qplot facet formulas are row_var ~ column_var with . standing in when one or the other is empty.