[R] Scatterplot - symbols coded by factor
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Sat Feb 10 09:51:34 CET 2001
On Fri, 9 Feb 2001, Matt Pocernich wrote:
> Hi - I would like to create a scatterplot with the symbols coded by a factor in each record. Is their a better way than what I have used below? I attempted to use the plot.factor, but cannot force it to make a scatterplot instead of boxplots. I have considerd making a function with a 'for' statement for each level of the factor. Is there a better way for when I am dealing with more levels of factors?
>
> Thanks, Matt Pocernich
>
> Y <- c(40,38,30,47,25,32,13,35,27,24,20,13)
> X<-c(110,75,93,97,60,75,38,140,62,90,45,59)
> manuf <- factor(rep(LETTERS[1:3],c(4,4,4)))
> data3 <- data.frame(X,Y,manuf)
> attach(data3)
>
> plot(X, Y, type="n")
> points(X[manuf=="A"], Y[manuf=="A"], pch = "A")
> points(X[manuf=="B"], Y[manuf=="B"], pch = "B")
> points(X[manuf=="C"], Y[manuf=="B"], pch = "C")
You can use
> plot(X, Y, type="n")
> points(X, Y, pch=as.character(manuf))
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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