0

に問題がありRます。北東の角から南に向かって、右側のプロット領域の外側に凡例を追加したいと思います。だから私はいくつかのコードを検索し、それを自分のコードに書きました。このコードで与えられた例は機能しますが、大きすぎるように見える私の凡例では機能しません。問題は、伝説の正しい位置を達成する方法です。

ここにいくつかのコードがあります:

#Construct some data and start the plot
x <- 0:64/64
y <- sin(3*pi*x)
plot(x, y, type="l", col="blue")
points(x, y, pch=21, bg="white")

#Grab the plotting region dimensions
rng <- par("usr")

#Call your legend with plot = FALSE to get its dimensions
lg <- legend(rng[1],rng[4] + lg$rect$h,xpd = NA,y.intersp=.75,c("Datenreihe 1", "Datenreihe 2", "lineare Regression\nfür Datenreihe 1", "lineare Regression\nfür Datenreihe 2"), pch = c(1,1,NA,NA), lty = c(NA,NA,1,1), col=c("lightblue","lightgreen","darkblue","darkgreen"),plot = FALSE)

#Once you have the dimensions in lg, use them to adjust
#the legend position
#Note the use of xpd = NA to allow plotting outside plotting region                 
legend(rng[1],rng[4] + lg$rect$h,xpd = NA,y.intersp=.75,c("Datenreihe 1", "Datenreihe 2", "lineare Regression\nfür Datenreihe 1", "lineare Regression\nfür Datenreihe 2"), pch = c(1,1,NA,NA), lty = c(NA,NA,1,1), col=c("lightblue","lightgreen","darkblue","darkgreen"),plot = TRUE)

前もって感謝します

4

0 に答える 0