将通用图例添加到多个 pROC 图

Add common legend to multiple pROC plots

我已经用 pROC 绘制了多条 ROC 曲线,现在我想在图的底部中心水平添加一个通用图例 space。我通常使用 ggplot,现在我迷失了基础 R 绘图。

这是我的代码:

# Set plotting parameters
par(mfrow=c(1,2), pty = "s", oma = c(4,1,1,1))

# ROC plot 1
roc(logit_A$y, logit_A$fitted.values, plot=TRUE, legacy.axes=FALSE, percent=TRUE, col="salmon", lwd=2, print.auc=TRUE)
plot.roc(logit_B$y, logit_B$fitted.values, percent=TRUE, col="goldenrod", lwd=2, print.auc=TRUE, add=TRUE, print.auc.y=40)
plot.roc(logit_C$y, logit_C$fitted.values, percent=TRUE, col="lightsteelblue", lwd=2, print.auc=TRUE, add=TRUE, print.auc.y=30)
title(main = "Model 1", line = 2.5)

# ROC plot 2
roc(logit_A2$y, logit_A2$fitted.values, plot=TRUE, legacy.axes=FALSE, percent=TRUE, col="salmon", lwd=2, print.auc=TRUE)
plot.roc(logit_B2$y, logit_B2$fitted.values, percent=TRUE, col="goldenrod", lwd=2, print.auc=TRUE, add=TRUE, print.auc.y=40)
plot.roc(logit_C2$y, logit_C2$fitted.values, percent=TRUE, col="lightsteelblue", lwd=2, print.auc=TRUE, add=TRUE, print.auc.y=30)
title(main = "Model 2", line = 2.5)

# Add legend
legend("bottom",
       legend=c("A", "B", "C"),
       col=c("salmon", "goldenrod", "lightsteelblue"),
       lwd=4, cex =0.4, xpd = TRUE, horiz = TRUE)

如何使图例位于两个图之间的底部居中?

你的意思是这样的吗:

  m <- matrix(c(1,2,3,3),nrow = 2,ncol = 2,byrow = TRUE)

layout(mat = m,heights = c(0.4,0.4))

for (i in 1:2){
  par(mar = c(2,2,1,1))
  plot(runif(5),runif(5),xlab = "",ylab = "")
}


par(mar=c(0,0,1,0))
plot(1, type = "n", axes=FALSE, xlab="", ylab="")
plot_colors <- c("blue","green","pink")
legend(x = "top",inset = 0,
       legend = c("AUC:72.9%", "AUC: 71.0%", "AUC:80.0%"), 
       col=plot_colors, lwd=7, cex=.7, horiz = TRUE)