I'm an R newbie. I'm plotting 4 approximation to a line. I want to put the legend on a top corner. I've tried:
legend(
"topleft", legend=....)
Then I tried to manually set the position still not working. Below is my code and my plot:
plot(1:N, vRm, pch=".", col="blue", xlab="m", ylim=c(0.885, 0.91))
ylab="approximated 90th percentile")
lines(1:N, v1m, pch=".", col="yellow")
lines(1:N, v2m, pch=".", col="green")
lines(1:N, v3m, pch=".", col="red")
legend(
y=0.92, legend=c("quantile","90st", "91st",
"(90st+91st)/2"), col=c("blue", "yellow", "green", "red"), pch=c(".",".", ".", ".")
)
and the plot:
how can I place the legend on a top corner?
In your legend definition, you don't define the option x in the the function legend. Notice the R reference:
The location may also be specified by setting x to a single keyword from the list "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right"
and "center"
. This places the legend on the inside of the plot frame at the given location. Partial argument matching is used. The optional inset argument specifies how far the legend is inset from the plot margins. If a single value is given, it is used for both margins; if two values are given, the first is used for x- distance, the second for y-distance.
So, you could place on the top rigth, for instance, with this command:
legend( x= "topright", y=0.92,
legend=c("quantile","90st", "91st", "(90st+91st)/2"),
col=c("blue", "yellow", "green", "red"),
pch=c(".",".", ".", "."))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With