Add legend to a plot with R
legend( "topleft", c("cars", "trucks", "cars1", "trucks1"),
text.col=c("blue", "red", "yellow", "green") )
Use the ?legend command to see options, such other locations on the graph, besides "topleft" or text size, whether to have a box around the legend, etc.
For example
legend(
"topright",
lty=c(1,2,1,2),
col=c("blue", "red", "yellow", "green"),
legend = c("cars", "trucks", "cars1", "trucks1")
)
See ?legend
.