次のような棒グラフがあります。
太字の長方形のどこかに凡例を追加したいので、par(xpd = TRUE)を試し、4番目の棒グラフのマージンを設定しましたが、何らかの理由で機能させることができません...
何かアイデアがあれば教えてください!
なぜxpd
うまくいかなかったのかはわかりませんが、次のコードからいくつかの手がかりが得られるはずです。
par(mfrow=c(2,2), xpd=TRUE)
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)
legend(-4.5, 56, c("A", "B"), col=2:3,lwd=1)
凡例の座標を知るために、このlocator()
関数を使用しました。
layout
ここでは、さまざまな高さで
使用できます
layout(rbind(c(1, 2),
c(3, 3),
c(4, 5)),
heights=c(3, 1.5, 3),
respect=FALSE)
tN <- table(Ni <- stats::rpois(100, lambda = 5))
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)
plot.new()
#box()
text(0.5,0.5,'legend in center',cex=3)
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)
試すlocator {graphics}
?locator
legend(locator(1), border=FALSE, fill=FALSE, "try the position")
plot()の後、希望する位置でプロットウィンドウをクリックできます