13

私はR初心者です。私は線に4つの近似をプロットしています。凡例を上隅に置きたい。私はもう試した:

legend(
"topleft", legend=....)

その後、手動で位置を設定しようとしましたが、まだ機能していません。以下は私のコードと私のプロットです:

 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(".",".", ".", ".")
 )

そしてプロット:

ここに画像の説明を入力

凡例を上の隅に配置するにはどうすればよいですか?

4

1 に答える 1

13

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(".",".", ".", "."))
于 2013-09-18T11:15:18.380 に答える