Labels with matplot
14,148
Sure, how about this?
a <- rnorm(100)
b <- 2*a + 3
c <- 3*a + 2
matplot(a, cbind(b,c), pch=1, col=c(2,4))
legend("bottomright", inset=.05, legend=c("b", "c"), pch=1, col=c(2,4), horiz=TRUE)
Brief explanations:
- bottomright is the location of the legend. you can use coordinates instead.
- insett is a distance from margin
- lengend, pch, and col arguments specify the content and style of the legend
- horz makes the legend displayed horizontally (suitable for short variable names)
Author by
user3213255
Updated on June 18, 2022Comments
-
user3213255 about 2 years
I created a plot with multiple lines using matplot:
matplot(a, cbind(b,c,d,e), pch=1)
where the arguments of cbind are functions of a, for example
b <- 2a+3 c <- 3a+2
and so forth.
How do add the corresponding labels to the resulting lines?