[R] Legend

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Sun Nov 13 13:46:59 CET 2005



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




More information about the R-help mailing list