(I'm new to R) Is there a way to add data to an existing plot, and have the plot axes rescaled automatically (i.e. if the new data lie outside the current axes) ? If not, how can I specify multiple datasets at once, so the axes are scaled to accomodate all sets? Details: (Am I using R's data structures in a reasonable way?) I have many small datasets taken under different conditions, and have placed the vectors of x-values into one list, and y-values into another. The lists are part of a data frame: expts$x[[1]] is a vector of x-coordinates for experiment 1, expts$y[[3]] is a vector of y-coordinates for experiment 3, etc. I want to plot experiments 1, 4, and 7 together on a single plot, and have the axes automatically scaled.> plot(expts$x[[1]], expts$y[[1]]) > points(expts$x[[4]], expts$y[[4]]) > points(expts$x[[7]], expts$y[[7]])This works, but won't rescale if experiment 4 has a wider range than experiment 1. I'm also open to better ways of structuring the data, if that helps. Right now, expts$temp (for example), is a column of the data frame containing the temperature at which each dataset is taken. I'd love to be able to ask for a plot of all datasets with (expts$temp == 25), for example. Or build a vector of experiment numbers and plot them all... thanks, -- Robert Merithew Laboratory of Atomic and Solid State Physics Cornell University, Ithaca, NY -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Sun, 30 Sep 2001 22:06:47 -0400 (EDT), you wrote:>(I'm new to R) > >Is there a way to add data to an existing plot, and have the plot axes >rescaled automatically (i.e. if the new data lie outside the current >axes) ?No, there's not. The scale is established by the first call.> >If not, how can I specify multiple datasets at once, so the axes are >scaled to accomodate all sets?You need to use the optional arguments xlim and ylim in the first call. Your example would look like this: plot(expts$x[[1]], expts$y[[1]], xlim = range(c(expts$x[[1]], expts$x[[4]], expts$x[[7]])), ylim = range(c(expts$y[[1]], expts$y[[4]], expts$y[[7]]))) (You might make do with something much simpler, like xlim = c(0,10), if you know the range of the data in advance, or want consistency across a wider range.) You also asked whether your data was organized well. I'd suggest not using a list, just use single x and y vectors, with another vector giving the experiment number. Then you could have something like plot(x[expt == 1], y[expt == 1], xlim = range(x[expt %in% c(1,4, 7)]), ylim = range(y[expt %in% c(1,4, 7)]) etc. Duncan Murdoch -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Robert, I didn't follow exactly how the data are set up -- I don't think that a data frame can be composed of lists, so I must misunderstand what you've done. But I can answer your plotting question. A general trick is to set up the plot to accommodate all of the data without plotting anything, by specifying type='n'. Then you can add the points. For example, suppose you have lists x and y composed of vectors: plot(range(unlist(x)), range(unlist(y)), type='n', xlab='x', ylab='y') for(i in seq(along=x)) points(x[[i]], y[[i]]) In your case, however, you don't seem to want to distinguish the different sets of points, so an even simpler approach would be to convert the lists into vectors to plot them directly: plot(unlist(x), unlist(y), xlab='x', ylab='y') I hope that this is of some help, John At 10:06 PM 30/09/2001 -0400, Robert D. Merithew wrote:>(I'm new to R) > >Is there a way to add data to an existing plot, and have the plot axes >rescaled automatically (i.e. if the new data lie outside the current >axes) ? > >If not, how can I specify multiple datasets at once, so the axes are >scaled to accomodate all sets? > > >Details: > >(Am I using R's data structures in a reasonable way?) > >I have many small datasets taken under different conditions, and have >placed the vectors of x-values into one list, and y-values into >another. The lists are part of a data frame: > >expts$x[[1]] is a vector of x-coordinates for experiment 1, >expts$y[[3]] is a vector of y-coordinates for experiment 3, etc. > >I want to plot experiments 1, 4, and 7 together on a single plot, and >have the axes automatically scaled. > > > plot(expts$x[[1]], expts$y[[1]]) > > points(expts$x[[4]], expts$y[[4]]) > > points(expts$x[[7]], expts$y[[7]]) > >This works, but won't rescale if experiment 4 has a wider range than >experiment 1. > >I'm also open to better ways of structuring the data, if that helps. > >Right now, expts$temp (for example), is a column of the data frame >containing the temperature at which each dataset is taken. I'd love to >be able to ask for a plot of all datasets with (expts$temp == 25), for >example. Or build a vector of experiment numbers and plot them all...----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Robert D. Merithew <merithew at ccmr.cornell.edu> writes:>(I'm new to R) > >Is there a way to add data to an existing plot, and have the plot axes >rescaled automatically (i.e. if the new data lie outside the current >axes) ? > >If not, how can I specify multiple datasets at once, so the axes are >scaled to accomodate all sets?Rescaling is not possible as the scale is set by the first call to plot(). If by "add data" you mean that you want to plot multiple data series and you now in advance which series you want to add then you should set ylim on the first plot() call to the range of the widest data series and then add the series to the initial plot. Mark -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._