Benjamin M. Osborne <Benjamin.Osborne <at> uvm.edu> writes: : : 1) When adding additional data sets to a plot using "plot" followed by "lines", : is there a way to automate the scaling of the axes to allow for all data sets : to fit within the plot area? : : 2) I attempted to solve this by setting : xlim=c(min(c(data1,data2,data3)),max(c(data1,data2,data3))) : however, there are some NAs and Infs in these data sets, and min(data1) and : max(data1) both return NA, as with data2 and data3. (These are time series).
Any of the following solutions would avoid having to calculate maximum and minimum in the first place: 1. You can first plot all the data together using type = "n" (no points are actually shown) and then add them one by one plot(c(x1,x2), c(y1,y2), type = "n") lines(x1, y1) lines(x2, y2) 2. you may be able to use matplot. See ?matplot . 3. if these are 'ts' class time series you could plot them all at once using ts.plot even if they have different time bases. See ?ts.plot 4. the 'zoo' library's plot function has facilities for plotting multiple time series all at once even if they have different time bases. See library(zoo); ?plot.zoo ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html