[R] 2 Trellis graphics question

Alan S Barnett asb at mail.nih.gov
Tue Jun 12 17:08:33 CEST 2007


1) I have a data that includes some "bad" data.  I want to make a
trellis plot where each panel contains 
a) A scatter plot of the "good" data
b) A scatter plot of the "bad" data in a different color
c) A best fit line of all the data, and
d) A best fit line of the "good" data.

I tried using xyplot and setting the "group" argument, but I'm having
trouble.  Here is my code:

xyplot(y ~ x | status, data=data,groups=good,
+  panel=function(x,y,...){
+  panel.xyplot(x,y,...)
+  panel.lmline(x,y,col = "red")
+  panel.lmline(x[good],y[good],col = "blue")
+ } 
+ )
a,groups=good,
data is a data frame containing names x, y and status.
good is logical variable labeling the "good" data.
Each panel of the trellis plot generated by this code includes
a) A scatterplot of the "good" data in magenta,
b) A scatterplot of the "bad" data in blue,
c) A best fit line of all the data in blue.

If I reverse the order of the last two lines, the best fit lines are
displayed in red.  Clearly, the correct value of good is not being
passed to panel.lmline, but is being correctly passed to panel.xyplot.

Substituting 
 panel.lmline(x,y,...)
for
 panel.lmline(x,y,col = "red") 
 panel.lmline(x[good],y[good],col = "blue)
results in the best fit line being plotted in black.
 
2) There are 5 different values of status, but I only want to plot three
of them.  Can I do this without copying only the desired elements into a
new data frame?

-- 
Alan S Barnett <asb at mail.nih.gov>
NIMH/CBDB



More information about the R-help mailing list