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

4

我有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?
谢谢!

“在右边”是指图例吗?另外,由于我们没有任何测试数据或calc_auc函数,因此无法重现。 - Axeman
添加 scale_color_manual 并定义 labelsbreaks。请查看这里 - missuse
1个回答

0

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接