简体   繁体   English

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

[英]add AUC by group on roc plots in R

I have roc plots for 4 groups, I want to add auc values for each group in the legend: 我有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

My plots looks like this: 我的情节看起来像这样: 在此输入图像描述 How can I add AUC to each group on the right? 如何在右侧的每个组中添加AUC?

Thanks! 谢谢!

您可以使用round(calc_auc(basicplot)[["AUC"]][1/2/3/4]提取calc_auc(basicplot)中的特定单元格,并将它们换成新句子。此外,您可能需要\\n打破几条新线的长句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM