4

これはおそらく古い質問ですが、満足のいく答えはどこにも見つかりません。次のコードがあるとします。

par(mfrow = c(2,1), mar = c(4,4,1,1), oma=c(2,2,2,2))
stuff <- c("ed", "bla")
cols <- c("red", "blue")
for(i in 1:length(stuff)) {
x <- rnorm(10,3,2)
y <- seq(1,10)
plot(x,y, type = "o", col = cols[i], xlab = paste("stuff about", stuff[i]))}
legend("bottomright", legend = stuff, col = cols, lwd = 1, bty = "n")
par(mfrow=c(1,1))
title(main = "ed & bla", outer = T)
mtext("This is a plot", 3, line=0.5, adj=1.0, cex=1, outer=TRUE)

プロットの下マージンに凡例を追加するにはどうすればよいですか?

ここに画像の説明を入力

4

2 に答える 2

3

プロット リクエストの順序を変更して、最後のプロットの直後 (ループの外側) で、次のプロット パラメータの変更前に凡例をプロットするようにします。「凡例」コマンドのみが移動されたことに注意してください。

par(mfrow = c(2,1), mar = c(4,4,1,1), oma=c(2,2,2,2))
stuff <- c("ed", "bla")
cols <- c("red", "blue")
for(i in 1:length(stuff)) {
x <- rnorm(10,3,2)
y <- seq(1,10)
plot(x,y, type = "o", col = cols[i], xlab = paste("stuff about", stuff[i]))}
legend("bottomright", legend = stuff, col = cols, lwd = 1, bty = "n")
par(mfrow=c(1,1))
title(main = "ed & bla", outer = T)
mtext("This is a plot", 3, line=0.5, adj=1.0, cex=1, outer=TRUE)

これにより、凡例が下のプロットの右下に配置されます。

于 2012-04-18T01:56:22.917 に答える
0

ただし、手動で座標を設定する必要があります

par(mfrow = c(2,1), mar = c(4,4,1,1), oma=c(2,2,2,2))
stuff <- c("ed", "bla")
cols <- c("red", "blue")
for(i in 1:length(stuff)) {
  x <- rnorm(10,3,2)
  y <- seq(1,10)
  plot(x,y, type = "o", col = cols[i], xlab = paste("stuff about", stuff[i]))}
legend(y=-5, x=5, legend = stuff, col = cols, lwd = 1, bty = "n", xpd=NA)
于 2016-10-27T13:55:07.660 に答える