[R] Legend symbol?

Sarah Goslee sarah.goslee at gmail.com
Thu Feb 4 21:41:47 CET 2010


So your question is actually about mixing lines and symbols in the legend?

What about:

plot(1:10, 1:10)
legend("topleft", legend=c("a", "b", "c"), lty=c(NA, -1, 1), pch=c(1, 2, NA))

Sarah

> ----- Original Message ----- From: "Douglas M. Hultstrand"
> <dmhultst at metstat.com>
> To: "R mailing list" <r-help at r-project.org>
> Sent: Thursday, February 04, 2010 4:59 PM
> Subject: [R] Legend symbol?
>
>
>> 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
>>


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list