Dear Mafalda,
?legend is what you are looking for. Take a look at the help page. Here is
one way to do what you asked for:

legend('topleft', c('A','B','C'),lty=1, col=c(1,2,4))

HTH,

Jorge


On Mon, May 11, 2009 at 11:26 AM, Mafalda Viana <via...@tcd.ie> wrote:

> Dear R users,
>
> I have what I think it is a very simple question concerning plots in R. If
> you could help me I would be very grateful.
>
> How can I include a legend in my plot? Below I give an example of my data
> and the code I am using.
>
> What I wish to accomplish is a legend saying that the black line refers to
> "A", the red to "B" and the blue to "C". Any suggestions?
>
>
> # data
> x<-c(1,2,3,4,5)
> y1<-c(2,4,6,8,10)
> y2<-c(3,4,5,6,7)
> y3<-c(2,3,5,7,9)
>
> # plot
> plot(x, y1, main="plot", type="l", xlab="x-axis", ylab="y-axis",
> col="black")
> lines(x, y2, col="red")
> lines(x, y3, col="blue")
>
> Thanking in advance.
>
> Best regards,
> Mafalda
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to