In the following snippet plot(1:10,1:10,type="n") points(1:5,1:5,pch="+") points(6:10,6:10,pch=20) legend(5,5, c("A","B"), pch=c("+",20)) I want to get a legend with a "+" and a solid circle (pch=20). However, what I get in the legend is "+" and "2". How can I get a "+" and a solid circle? thanks, Steve > sessionInfo() R version 2.6.1 (2007-11-26) i686-pc-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices datasets utils methods base loaded via a namespace (and not attached): [1] rcompgen_0.1-17
Henrique Dallazuanna
2008-Jan-23 18:04 UTC
[R] How do I get a character and a symbol in a legend
Try: plot(1:10,1:10,type="n") points(6:10,6:10,pch=20) points(1:5,1:5,pch=3) legend(5,5, c("A","B"), pch=c(3,20)) On 23/01/2008, steve <fisk at bowdoin.edu> wrote:> In the following snippet > > plot(1:10,1:10,type="n") > points(1:5,1:5,pch="+") > points(6:10,6:10,pch=20) > legend(5,5, c("A","B"), pch=c("+",20)) > > I want to get a legend with a "+" and a solid circle (pch=20). > However, what I get in the legend is "+" and "2". How can I get a "+" > and a solid circle? > > thanks, Steve > > > sessionInfo() > R version 2.6.1 (2007-11-26) > i686-pc-linux-gnu > > locale: > LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices datasets utils methods base > > loaded via a namespace (and not attached): > [1] rcompgen_0.1-17 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Peter Dalgaard
2008-Jan-23 18:10 UTC
[R] How do I get a character and a symbol in a legend
steve wrote:> In the following snippet > > plot(1:10,1:10,type="n") > points(1:5,1:5,pch="+") > points(6:10,6:10,pch=20) > legend(5,5, c("A","B"), pch=c("+",20)) > > I want to get a legend with a "+" and a solid circle (pch=20). > However, what I get in the legend is "+" and "2". How can I get a "+" > and a solid circle? > >Hmm... There seems to be no way around having all pch's of the same type, because it has to be a single vector. So what you need to do is to find the integer code for "+". This happens to be the same as its ASCII code which is 43. One slightly sneaky way of finding that out is> as.integer(charToRaw("+"))[1] 43 -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907