[R] pch with plot and legend

John Verzani verzani at math.csi.cuny.edu
Wed Jul 25 18:45:27 CEST 2001


I'm trying to plot a scatterplot of two variables using pch to plot
different characters based on a third factor. Here is my example

> data("ToothGrowth")
> attach(ToothGrowth)
> levels(supp)
[1] "OJ" "VC"
> plot(len ~ dose,pch=as.numeric(supp))
> legend(locator(1),pch=as.numeric(supp),legend=levels(supp))

The command as.numeric(supp) returns 2 2 2 2 ...  1 1 1 ... for the
factor supp which the plot command uses nicely, but the pch command
for the legend uses the first two values 2 2 for the command. This
isn't correct of course. How can I get the correct numbers for the pch 
command for the levels? I tried pch=as.numeric(levels(supp)) in legend 
but that didn't work. 

Thanks for any help.

John

-- 
....................................................................
.  John Verzani                  mailto:verzani at math.csi.cuny.edu  .
.  Dept. of Mathematics      http://www.math.csi.cuny.edu/~verzani .
.  City University of New York                 tel: (718) 982-3623 .
.  College of Staten Island                    fax: (718) 982-3631 .
.  Staten Island, NY 10314                                         .
....................................................................
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list