[R] Legend

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Sun Nov 13 14:07:28 CET 2005


And you want to have different colored lines but black texts, try

 legend(x = 5, y = 0.2, legend = c("Data Set", "Fitted PDF"),
        col = c("black", "red"), lty=1)

The advantage of this is that you can use dotted (lty option) or lines
with different weights (lwd option).

Regards, Adai



On Sun, 2005-11-13 at 06:46 -0600, Sundar Dorai-Raj wrote:
> 
> Mark Miller wrote:
> > I use the following to plot two graphs over each other and then insert a 
> > legend, but the two items in the legend both come up the same colour
> > 
> > x = seq(0,30,0.01)
> > plot(ecdf(complete), do.point=FALSE, main = 'Cummlative Plot of Monday IATs 
> > for Data and\n Fitted PDF over Entire 15 Weeks')
> > lines(x, pexp(x,0.415694806),col="red")
> > legend(x=5,y=0.2 , legend=c("Data Set","Fitted PDF"),col=c("black","red"))
> > 
> > Many thanks
> > Mark Miller
> > 
> 
> Hi, Mark,
> 
> You want to use "text.col" in legend instead of "col":
> 
> set.seed(1)
> z <- rexp(30, 0.415694806)
> x <- seq(0, 30, 0.1)
> plot(ecdf(z), do.point = FALSE)
> lines(x, pexp(x, 0.415694806), col="red")
> legend(x = 5, y = 0.2, legend = c("Data Set", "Fitted PDF"),
>         text.col = c("black", "red"))
> 
> --sundar
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list