[R] Legend symbol?

Chris Campbell clc559 at gmail.com
Thu Feb 4 21:50:56 CET 2010


On Thu, Feb 4, 2010 at 14:59, Douglas M. Hultstrand
<dmhultst at metstat.com> wrote:
> Hello,
>
> I am creating a plot/image using different data and a couple fit lines (see
> attached image).  In the legend, I want the Default and Exponential symbol
> to be a line.  I am using the pch command, I tried to use "-" to represent a
> line but does not work so I currently have set as a "1".  Any thoughts or
> suggestions would be greatly appreciated.
>
> Below are the commands I used to create the legend:
> if(Prehour == 1) {
>       leg.txt <- c("Data", "Statistical Outlier", "Spatial Outlier", "High Z
> Outlier", "Default","Exponential (used)")
>       } else {
>       leg.txt <- c("Data", "Statistical Outlier", "Spatial Outlier", "High Z
> Outlier", "Default (used)","Exponential")
> }
> legend("topleft", legend=leg.txt,
> col=c("black","yellow","red","orange","blue","black"), pch =
> c(16,16,16,16,1,1), cex=0.85 )
>
> Thanks,
> Doug
>
> --
> ---------------------------------
> Douglas M. Hultstrand, MS
> Senior Hydrometeorologist
> Metstat, Inc. Windsor, Colorado
> voice: 970.686.1253
> email: dmhultst at metstat.com
> web: http://www.metstat.com
> ---------------------------------
>
>
> ______________________________________________
> 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.
>
>

You can combine pch and lty in the legend call.  Try:

legend("topleft", legend=leg.txt,
col=c("black","yellow","red","orange","blue","black"), pch =
c(16,16,16,16,NA,NA),lty=c(rep(NA,4),1,1), cex=0.85 )

Also, try to stay away from the yellow color; it's very hard to make
out against a white background.



More information about the R-help mailing list