Skip to content

Adding legends to a plot

2 messages · liujb, Jorge Ivan Velez

#
Hello,

I have a time series plot drawn using 3 different colored lines, each line
corresponds to different category group. I'd like to put legends on the
plot. I am using "legend" to do this, however, I can either specify lty or
col in legend. Will I be able to do the following in the legend box: a solid
black line then g1, a solid red line then g2, a solid blue line then g3?

plot(g1, ylim=c(0,10))
lines(g2, col="red")
lines(g3, col="blue")
legend(locator(n=1), legend=c("g1", "g2", "g3"), ???)

Thank you very much,
sincerely
Julia