I'm trying to plot four different sorghum types on a plot using a different colour/symbol combination for each sorghum type (TYPBOTA in the script below). What am I doing wrong?: plot(xx$LATITUDE,xx$SFD1, points(xx$SFD1,xx$LATITUDE, col=1:4[codes(xx$TYPBOTA)],pch=c(4,3,1,2)[codes(xx$TYPBOTA)]) grid() I get the following error message Error in 1:4[codes(xx$TYPBOTA)] : NA/NaN argument In addition: Warning message: Numerical expression has 162 elements: only the first used in: 1:4[codes(xx78$TYPBOTA)] Best wishes, Mikkel Mikkel Grum, PhD Genetic Diversity Scientist International Plant Genetic Resources Institute (IPGRI) Sub-Saharan Africa Group *** c/o ICRAF PO Box 30677 Nairobi, Kenya Tel: 254 2 524505 / 524500 Fax: 254 2 524501 / 524001 IVDN Tel: 645 4505 / 4500 IVDN Fax: 645 4501 / 4001 m.grum at cgiar.org ipgri-kenya at cgiar.org www.ipgri.cgiar.org -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2002-Jan-08 15:03 UTC
[R] colour coding and different point types in a plot
"Grum, Mikkel" <M.GRUM at CGIAR.ORG> writes:> I'm trying to plot four different sorghum types on a plot using a different > colour/symbol combination for each sorghum type (TYPBOTA in the script > below). What am I doing wrong?: > > plot(xx$LATITUDE,xx$SFD1, > points(xx$SFD1,xx$LATITUDE, > col=1:4[codes(xx$TYPBOTA)],pch=c(4,3,1,2)[codes(xx$TYPBOTA)]) > grid() > > I get the following error message > Error in 1:4[codes(xx$TYPBOTA)] : NA/NaN argument > In addition: Warning message: > Numerical expression has 162 elements: only the first used in: > 1:4[codes(xx78$TYPBOTA)]I think you need (1:4)[...] (and maybe also reconsider the use of codes(). It has certain surprises, and indexing with a factor is the same as using foo[as.integer(f)]) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Martin Maechler
2002-Jan-08 15:07 UTC
[R] colour coding and different point types in a plot
>>>>> "MGrum" == Grum, Mikkel <M.GRUM at CGIAR.ORG> writes:MGrum> I'm trying to plot four different sorghum types on a MGrum> plot using a different colour/symbol combination for MGrum> each sorghum type (TYPBOTA in the script below). MGrum> What am I doing wrong?: -- you mean, apart from using hard/horrible to read all-uppercase variable names :-)) aka `big grin' - MGrum> plot(xx$LATITUDE,xx$SFD1, I assume this command goes on and is finished in your real example .. MGrum> points(xx$SFD1,xx$LATITUDE, MGrum> col=1:4[codes(xx$TYPBOTA)],pch=c(4,3,1,2)[codes(xx$TYPBOTA)]) MGrum> I get the following error message MGrum> Error in 1:4[codes(xx$TYPBOTA)] : NA/NaN argument MGrum> In addition: Warning message: MGrum> Numerical expression has 162 elements: only the first used in: MGrum> 1:4[codes(xx78$TYPBOTA)] Maybe look at this ? > 1:4[c(3,1,2,NA,4,2)] Error in 1:4[c(3, 1, 2, NA, 4, 2)] : NA/NaN argument In addition: Warning message: Numerical expression has 6 elements: only the first used in: 1:4[c(3, 1, 2, NA, 4, 2)] > (1:4)[c(3,1,2,NA,4,2)] [1] 3 1 2 NA 4 2 Morale of the story: always use "(..)" when in doubt Regards, Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thanks to all, the brackets worked. The variable names are the costs of collaboration :), certainly not my preference. mikkel -----Original Message----- From: Martin Maechler [mailto:maechler at stat.math.ethz.ch] Sent: 08 January 2002 18:08 To: Grum, Mikkel Cc: R-help at stat.math.ethz.ch Subject: Re: [R] colour coding and different point types in a plot>>>>> "MGrum" == Grum, Mikkel <M.GRUM at CGIAR.ORG> writes:MGrum> I'm trying to plot four different sorghum types on a MGrum> plot using a different colour/symbol combination for MGrum> each sorghum type (TYPBOTA in the script below). MGrum> What am I doing wrong?: -- you mean, apart from using hard/horrible to read all-uppercase variable names :-)) aka `big grin' - MGrum> plot(xx$LATITUDE,xx$SFD1, I assume this command goes on and is finished in your real example .. MGrum> points(xx$SFD1,xx$LATITUDE, MGrum> col=1:4[codes(xx$TYPBOTA)],pch=c(4,3,1,2)[codes(xx$TYPBOTA)]) MGrum> I get the following error message MGrum> Error in 1:4[codes(xx$TYPBOTA)] : NA/NaN argument MGrum> In addition: Warning message: MGrum> Numerical expression has 162 elements: only the first used in: MGrum> 1:4[codes(xx78$TYPBOTA)] Maybe look at this ? > 1:4[c(3,1,2,NA,4,2)] Error in 1:4[c(3, 1, 2, NA, 4, 2)] : NA/NaN argument In addition: Warning message: Numerical expression has 6 elements: only the first used in: 1:4[c(3, 1, 2, NA, 4, 2)] > (1:4)[c(3,1,2,NA,4,2)] [1] 3 1 2 NA 4 2 Morale of the story: always use "(..)" when in doubt Regards, Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._