Add legend to a plot with R
<p>I create 4 line in one plot using R .
Here the code</p>

<pre><code># Define 2 vectors
cars &lt;- c(123.07, 110.51, 96.14, 98.71, 101.3)
trucks &lt;- c(110.31, 89.91, 89.81, 89.31, 93.4, 95.81)
cars1 &lt;- c(123.227, 110.221, 93.14, 98.22, 122.3)
trucks1 &lt;- c(120.31, 89.91, 89.81, 89.31, 93.4, 95.81)
# Graph cars using a y axis that ranges from 0 to 12
plot(cars, type="o", col="blue", ylim=c(80,130))

# Graph trucks with red dashed line and square points
lines(trucks, type="o", pch=22, lty=2, col="red")
lines(cars1, type="o", col="yellow", ylim=c(80,130))

# Graph trucks with red dashed line and square points
lines(trucks1, type="o", pch=22, lty=2, col="green")
# Create a title with a red, bold/italic font
title(main="Autos", col.main="red", font.main=4)
</code></pre>

<p>I would like to know how can I add the legend for each plot (line) in the plot.</p>

<p>Thank you</p>