Hi I am trying to plot two data set in the same picture window without overlapping with each other. I am using the format plot(x1,y1,x2,y2) but get the following error message:>plot(as.numeric(r0[,4]),as.numeric(r0[,7]),as.numeric(r0[,4]),as.numeric(r0[,7][ind[,1]]))Error in plot.window(xlim, ylim, log, asp, ...) : invalid 'ylim' value Can anyone tell me what went wrong? Thanks. Eric
Joerg van den Hoff
2006-Jun-13 07:29 UTC
[R] plot two graphs with different length of data
Eric Hu wrote:> Hi I am trying to plot two data set in the same picture window without > overlapping with each other. I am using the format plot(x1,y1,x2,y2) > but get the following error message: > >> plot(as.numeric(r0[,4]),as.numeric(r0[,7]),as.numeric(r0[,4]),as.numeric(r0[,7][ind[,1]])) > Error in plot.window(xlim, ylim, log, asp, ...) : > invalid 'ylim' value > > Can anyone tell me what went wrong? Thanks. > > Eric > > ______________________________________________ > R-help at 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.htmlmatplot(cbind(x1,x2), cbind(y1,y2)) might be what you want. (if x1, x2 and y1,y2 are of equal length. otherwise pad the short ones with NAs or use `matplot' with type =n (to get the scaling of the plot right), followed by `plot(x1,y1), lines(x2,y2)')
Eric Hu wrote:> Hi I am trying to plot two data set in the same picture window without > overlapping with each other. I am using the format plot(x1,y1,x2,y2) > but get the following error message: > > >>plot(as.numeric(r0[,4]),as.numeric(r0[,7]),as.numeric(r0[,4]),as.numeric(r0[,7][ind[,1]])) > > Error in plot.window(xlim, ylim, log, asp, ...) : > invalid 'ylim' value > > Can anyone tell me what went wrong? Thanks.plot is probably interpreting one of your data vectors as the ylim argument. If you want to plot multiple data series of different lengths, it is probably simplest to use points() (or lines()) after plotting the first one. For an example of this, see: http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_addat.html Jim