[R] plot.formula

Adrian Baddeley adrian at asteridia.maths.uwa.edu.au
Tue Jun 17 12:55:11 CEST 2003


Thanks to Andy Liaw and Baz 
for alternatives to tinkering with plot.formula
to get
	plot(cbind(y1,y2) ~ x, ...)
to work.

However...

   > From: "Liaw, Andy" <andy_liaw at merck.com>
    matplot(x, cbind(y1, y2), ...)

   > From: Barry Rowlingson <B.Rowlingson at lancaster.ac.uk>
   xyplot(y1+y2~x,data=xyy,allow.multiple=T)

The former requires separate code for the case of multiple response variables.

The latter does provide a formula interface, but the interpretation
of the formulae is inconvenient. 
For example

   - if y1 is an expression containing "+"
      then it would have to be protected by I() to prevent the 
      summands in the expression being plotted separately.
      
   - you can't replace one of the response variables by a constant, 
   as this will be evaluated as a vector of length 1.

It's a lot easier with cbind() , for example

     plot(cbind(z1 -zhat + bias, 0) ~ x)

gets you a plot of (z1-zhat+bias) versus x 
together with a horizontal line at y=0. 

The idea of using cbind() was indeed modelled on the glm() usage.

----
Adrian Baddeley, Mathematics & Statistics, University of Western Australia
		<http://maths.uwa.edu.au/~adrian/>




More information about the R-help mailing list