Problem with legend

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with legend

Komine
HI,
This code is part of a code I used to do a linear regression:

>points(var1~var2,data=Regress,pch=21,bg="grey")
>reg11<-lm(var1~var2,data=Regress)
>abline(lm(var1~var2,data=Regress),lty=2,lwd=2,col="grey")
>legend("topleft",legend=
>c("NDII from composite",  
>"y= 0.0007x - 0.1156",expression(paste(r^2 == 0.88)),"p-value <0.001"),
>pch=21,
>bty="n")

But I have a problem to complete the legend.
Indeed, on the legend, I want to display a point  in front "Ndii from composite images." But when I run my code I get a point in front, "Ndii from composite images" but also before "y = 0.0007x - 0.1156", "r ^ 2 == 0.88," " and " p-value <0.001 "."
How can I do to obtain only one point in front "Ndii from composite images"?
Thank you in advance
Reply | Threaded
Open this post in threaded view
|

Re: Problem with legend

PtitBleu
This post was updated on .
Maybe by adding
col=c("grey","white","white"), bg="white"
but not sure ...

Have a nice end of day,
Ptit Bleu.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with legend

Sarah Goslee
In reply to this post by Komine
You're passing a vector of length 3 to the legend argument of legend(), so R is
assuming that you have three things you want to display.

There are two alternatives:
1. Provide legend() a legend that's a single character vector.
2. Specify that you don't want symbols for the last two of the three legend
components by using pch=c(21, NA, NA).

Sarah

On Tue, Sep 20, 2011 at 10:13 AM, Komine <[hidden email]> wrote:

> HI,
> This code is part of a code I used to do a linear regression:
>
>>points(var1~var2,data=Regress,pch=21,bg="grey")
>>reg11<-lm(var1~var2,data=Regress)
>>abline(lm(var1~var2,data=Regress),lty=2,lwd=2,col="grey")
>>legend("topleft",legend=
>>c("NDII from composite",
>>"y= 0.0007x - 0.1156",expression(paste(r^2 == 0.88)),"p-value <0.001"),
>>pch=21,
>>bty="n")
>
> But I have a problem to complete the legend.
> Indeed, on the legend, I want to display a point  in front "Ndii from
> composite images." But when I run my code I get a point in front, "Ndii from
> composite images" but also before "y = 0.0007x - 0.1156", "r ^ 2 == 0.88," "
> and " p-value <0.001 "."
> How can I do to obtain only one point in front "Ndii from composite images"?
> Thank you in advance
>
>



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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with legend

Komine
Thank you Sarah and Petit bleu for your help.
I solved my problem with the code of Sarah.

Komine