r - 在 R 中的 roc 图上按组添加 AUC

标签 r ggplot2 label roc

我有 4 个组的 roc 图,我想为图例中的每个组添加 auc 值:

## draw plots
basicplot <- ggplot(roc_long, aes(d = outcome, m = prediction, color = model)) + geom_roc(n.cuts = 0) + 
+   style_roc(theme = theme_bw, xlab = "1-Specificity", ylab = "Sensitivity") 
## calculate auc
calc_auc(basicplot)
      PANEL group       AUC
    1     1     1 0.7718926
    2     1     2 0.9296029
    3     1     3 0.7790979
    4     1     4 0.8235286

annotate <- basicplot + 
     ggtitle("ROC plots for 4 outcomes") +
     theme(plot.title = element_text(hjust = 0.5)) +
     annotate("text", x = .75, y = .25, label = paste("AUC =", round(calc_auc(basicplot)["AUC"], 3)))

     annotate

我的情节是这样的:
enter image description here
如何将 AUC 添加到右侧的每个组?

谢谢!

最佳答案

您可以使用 round(calc_auc(basicplot)[["AUC"]][1/2/3/4] 提取 calc_auc(basicplot) 中的特定单元格, 并将它们包装在一个新句子中。您也可能需要 \n在几个新行上打破长句。

关于r - 在 R 中的 roc 图上按组添加 AUC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47820166/

相关文章:

R 在显示或打印命名向量时抑制名称

regex - 基于R中的点拆分文本

使用 ggplot2 绘制来自 Geotiff 的 R 背景图

r - 在 ggplot 中将 x 轴标签指向内

eclipse - Birt 报告,带操作的动态标签

r - 在多面 ggplot 中自动勾选最大值和最小值

r - 通过 2 个变量聚合一个值

r - R ggplot geom_tile没有填充颜色

r - 如何更改 ggplot2 图例的标题?

带分数的 r 标签图