[R] different data series on one graph
Achim Zeileis
zeileis at ci.tuwien.ac.at
Fri Apr 26 23:24:19 CEST 2002
wouter.buytaert at yucom.be wrote:
>
> Hello,
>
> I'm looking for a way to plot different data series on one graph.
> I have a series of hourly rainfall and quarterly flow
> measurements (i.e. 4 times an hour) of a catchment. The rainfall
> should be plotted in bars, the flow as a line. Both on the same X
> axe (time) but with different Y axes.
>
> The problem is the plot() function does not support add=TRUE...
>
> Furthermore I'm not sure what's the best format for input data.
> Now it are two data frames with a time (POSIXct) and a
> rainfall/flow part. Maybe time series are easier, but in
>
> ts(data = NA, start = X,...
>
> X should be a number or a vector. how does this coresponds to a
> data and hour (e.g. april 26,2002, 15:00:00)?
If your observations are equidistant, e.g. you've got 24 hourly
measurements per day, you could do something like this for the above
example:
R> rain <- ts(rain, start = c(26, 15), freq = 24)
R> flow <- ts(flow, start = c(26, 15), freq = 96)
and then you can just do
R> plot(rain)
R> lines(flow, col = 2)
for a time series plot.
If the observations are not equally spaced, then it is probably the
easiest thing to get a vector of dates on a reasonable scale (days or
something like that) and then do:
R> plot(time.rain, rain, type = "l")
R> lines(time.flow, flow, col = 2)
Hope this helps
Z
> Thanks,
>
> Wouter Buytaert
> Institute for Land and Water Management
> Katholieke Universiteit Leuven
>
> ---------------------------------------------------------------
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list