我将多个图连接成一个图(具体为 24 个),我不太清楚如何为整个图添加图例。
par(mfrow = c(4,6))
for(i in 1:24){
x <- rep(0,3)
y <- rnorm(3, 3)
par(family = "Garamond")
col_vec <- c( "darkblue", "gray65", "maroon4")
plot(x,y, xaxt = 'n', xlab = '', ylab = '', xaxt='n', bty = "n", ylim = c((min(y) - 1.5),(max(y) + 1.5)), col = col_vec, pch = 19, cex =.8)
abline(h=y[2], lty=2, col = "gray89")}
title("Effect Size", outer = TRUE, line = -2, cex = 2)
legend("topleft", c("Treatment 1", "Control", "Treatment 2"), col = col_vec, pch = 15)
如果有人知道如何将图例添加到左侧而不是每个图或所有图,那就太好了;请注意,如果没有 legend 命令,上面的代码会生成下图: