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") -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20010209/5db1c70d/attachment.html
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Matt Pocernich wrote:> Hi - I would like to create a scatterplot with the symbolscoded by a> factor in each record. Is their a better way than what Ihave used> below? I attempted to use the plot.factor, but cannot forceit to> make a scatterplot instead of boxplots. I have considerdmaking 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 offactors?> Thanks, Matt Pocernich >You can use the function text. plot(X,Y,type='n') text(X, Y, labels = as.character(manuf)) -- =============================================================Alvaro Colina |-|o||o||o||o||o||o||o||o||o|- Area de Quimica Analitica | Pza. Misael Banuelos s/n Facultad de Ciencias | 09001. Burgos. Spain Universidad de Burgos | Phone: 34-947-258817 e-mail: acosa at ubu.es | FAX: 34-947-258831 ============================================================= -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
At 08:51 10/02/01 +0000, Brian D Ripley wrote:>On Fri, 9 Feb 2001, Matt Pocernich wrote: > >> Hi - I would like to create a scatterplot with the symbols coded by afactor 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))The following (inspired from demo(graphics)) may also be useful: plot(X, Y, pch=levels(manuf)[codes(manuf)]) The example in demo(graphics) shows a case where the user wants different colours for the symbols with respect to a factor (here the Iris species): pairs(iris[1:4], main = "Edgar Anderson's Iris Data", pch = 21, bg = c("red", "green3", "blue")[codes(iris$Species)]) Emmanuel Paradis -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._