Could I suggest the following extension to plot.formula: plot(cbind(y1,y2) ~ x, ...) should plot (y1 against x) and (y2 against x) on the same plot. The default y axis limits would be determined by the range of c(y1,y2). This would be pretty handy sometimes, replacing 4 lines of code. The current plot.formula evaluates cbind(y1,y2), which is a matrix, so plot.formula looks for "plot.matrix", in vain, then calls plot.default which gives an error because length(cbind(y1,y2)) is greater than length(x). I suggest that plot.formula be changed to recognise the situation where there is more than one response variable, and produce multiple superimposed plots in that case. (It already recognises the case where there are multiple non-response variables). ---- Adrian Baddeley, Mathematics & Statistics, University of Western Australia <http://maths.uwa.edu.au/~adrian/>
This is typically done with matplot(x, cbind(y1, y2), ...), so there's only one line of code needed. Perhaps you want a formula interface for matplot? Andy> -----Original Message----- > From: Adrian Baddeley [mailto:adrian at asteridia.maths.uwa.edu.au] > Sent: Monday, June 16, 2003 5:53 AM > To: r-help at stat.math.ethz.ch > Subject: [R] extension to plot.formula? > > > Could I suggest the following extension to plot.formula: > > plot(cbind(y1,y2) ~ x, ...) > > should plot (y1 against x) and (y2 against x) on the same plot. > > The default y axis limits would be determined by the range of > c(y1,y2). > > This would be pretty handy sometimes, replacing 4 lines of code. > > The current plot.formula evaluates cbind(y1,y2), which is a > matrix, so plot.formula looks for "plot.matrix", in vain, > then calls plot.default which gives an error because > length(cbind(y1,y2)) is greater than length(x). > > I suggest that plot.formula be changed to recognise the > situation where there is more than one response variable, and > produce multiple superimposed plots in that case. (It already > recognises the case where there are multiple non-response variables). > > ---- > Adrian Baddeley, Mathematics & Statistics, University of > Western Australia > <http://maths.uwa.edu.au/~adrian/> > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, cont... {{dropped}}
Adrian Baddeley wrote:> Could I suggest the following extension to plot.formula: > > plot(cbind(y1,y2) ~ x, ...) > > should plot (y1 against x) and (y2 against x) on the same plot. >Trellis - er - lattice graphics uses a similar approach, but you use '+', and give another argument, allow.multiple: xyplot(y1+y2~x,data=xyy,allow.multiple=T) I'm no great user of lattice graphics, so I leave it to someone else to tell us how to join the dots with lines. The cbind() approach has a precedent in glm(cbind(y,n)~x,family=binomial) Although I've always found plotting with formulas a bit ugly, since the 'x' and 'y' are in reverse alphabetic order and I could be plotting things that conceptually have no formulaic relationship - x and y geographic coordinates, for instance. In a modelling context you can read the ~ as 'depends on', but not necessarily in a plot! Baz