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)? 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "wouter" == wouter buytaert <wouter.buytaert at yucom.be> writes:wouter> Hello, wouter> I'm looking for a way to plot different data series on one graph. wouter> I have a series of hourly rainfall and quarterly flow wouter> measurements (i.e. 4 times an hour) of a catchment. The rainfall wouter> should be plotted in bars, the flow as a line. Both on the same X wouter> axe (time) but with different Y axes. wouter> The problem is the plot() function does not support add=TRUE... lines() and points() should work for you. -- A.J. Rossini Rsrch. Asst. Prof. of Biostatistics U. of Washington Biostatistics rossini at u.washington.edu FHCRC/SCHARP/HIV Vaccine Trials Net rossini at scharp.org -------------- http://software.biostat.washington.edu/ ---------------- FHCRC: M-W: 206-667-7025 (fax=4812)|Voicemail is pretty sketchy/use Email UW: Th: 206-543-1044 (fax=3286)|Change last 4 digits of phone to FAX (my friday location is usually completely unpredictable.) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Here is a function that can be easily modified for your purposes. Example of usage: x2 <- 0:12 y1 <- x1^2 y2 <- x2+3 plot.double(x1,y1,x2,y2,lty1=1,lty2=3,pch2=1,type1="b",type2="h") "plot.double" <- function(x1, y1, x2, y2, type1 = "l",type2="l", xlim NULL, main = NULL, xlab = NULL,lty1=1,lty2=2,pch2=16,pch1=1, ylab1 = "y1", ylab2 = "y2", ...) { # Written by AE York Sept. 1996 for Splus; converted to R Jan 2001 # Plots y1 vs x1 and y2 vs x2 on the same plot types type1 and type2 # Labels for y1 are on the left and labels for y2 on the right oldpar <- par() par(mar = rep(6, 4)) # if(missing(xlim)) xlim <- range(pretty(range(c(x1, x2)))) plot(x1, y1, lty = lty1, pch = pch1, type = type1, xlim = xlim, xlab = xlab, ylab = ylab1, ...) par(new = T) plot(x2, y2, lty = lty2, pch = pch2, type = type2, axes = F, xlim xlim, xlab = "", ylab = "") axis(side = 4) mtext(ylab2, side = 4, line = 2, outer = F) title(main=main) par(mar=oldpar$mar) } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Anne E. York National Marine Mammal Laboratory Seattle WA 98115-0070 USA e-mail: anne.york at noaa.gov Voice: +1 206-526-4039 Fax: +1 206-526-6615 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On Fri, 26 Apr 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)? > >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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._