使用pROC向AUC标签添加文本

问题描述 投票:1回答:1

我想知道是否有办法在我的ROC图上进一步注释已打印的AUC?

目前,不清楚我的绘图中AUC属于哪条线(如下)。我想添加更多描述,以使文本看起来像:

  • FI的AUC:0.506
  • FP的AUC:0.468

在pROC :: roc()函数中是否可以执行此操作?

enter image description here

这是使用测试数据的可生产示例:

library(pROC)

testdata = structure(list(outcome = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c("0", 
"1"), class = "factor"), fi = c(0.0395, 0.0835, 0.03975, -0.079, 
-0.00825000000000001, NA, NA, -0.0125, -0.04175, -0.09375, -0.02275, 
0.01675, 0.03325, -0.0165, 0.0165, 0.0585, -0.04175, NA, -0.004, 
0.05, 0.0165, -0.0335, -0.01225, -0.025, 0.01225, NA, 0.05425, 
0.08125, 0.07925, NA, NA, -0.00625, 0.05, 0.06875, NA, 0.0645, 
NA, -0.00625000000000001, 0.03125, 0.07275, 0.00625, 0.027, 0.0665, 
0.023, 0.046, -0.1875, -0.2, -0.002, -0.10225, 0.0605), fp = c(-2, 
-1, -1, -1, 0, NA, NA, 0, 0, -1, 1, 0, 0, 1, NA, NA, -1, NA, 
0, NA, NA, NA, NA, NA, 0, NA, NA, 1, NA, NA, NA, 1, 1, -1, NA, 
NA, NA, 0, 0, NA, 1, 0, NA, 0, 1, 1, 2, 0, 0, -1)), class = "data.frame", row.names = c(NA, 
-50L))


par(pty="s") # change the graphical parameter pty to s before calling plot.roc so that the margins are outside the plot
plot(roc(testdata[["outcome"]], testdata[["fi"]]), print.auc=TRUE, col="black", lty=1, lwd=2, legacy.axes = TRUE, print.auc.y=.35, grid=TRUE)
plot(roc(testdata[["outcome"]], testdata[["fp"]]), print.auc=TRUE, col="black", lty=3, lwd=2, legacy.axes = TRUE, print.auc.y=.3, grid=TRUE, add=TRUE)
legend("bottomright",
       legend=c("Frailty Index", "Frailty Phenotype"),
       col=c("black", "black"),
       lty=c(1,3),
       lwd=c(2,2))
myroc = recordPlot() # saves current plot
r plot roc auc proc-r-package
1个回答
2
投票

您可以设置print.auc=FALSE,然后使用text添加文本:

roc_fi <- roc(testdata[["outcome"]], testdata[["fi"]])
roc_fp <- roc(testdata[["outcome"]], testdata[["fp"]])

plot(roc_fi, print.auc=FALSE, col="black", lty=1, lwd=2, legacy.axes = TRUE, print.auc.y=.35, grid=TRUE)
plot(roc_fp, print.auc=FALSE, col="black", lty=3, lwd=2, legacy.axes = TRUE, print.auc.y=.3, grid=TRUE, add=TRUE)
legend("bottomright",
       legend=c("Frailty Index", "Frailty Phenotype"),
       col=c("black", "black"),
       lty=c(1,3),
       lwd=c(2,2))

text(0.4, 0.4, paste("AUC for FI:", round(roc_fi$auc, 3)))
text(0.4, 0.35, paste("AUC for FP:", round(roc_fp$auc, 3)))
© www.soinside.com 2019 - 2024. All rights reserved.