I create a plot that shows to ROC objects using
rocobj <- pred1
rocobj1 <- pred2
ggroc(list(sc1 = rocobj, sc2 = rocobj1))
and I'd like to add information about each curve. Previously, I used:
annotate("text",x=0.15,y=0.1,label=paste0("\nloss: ", out[[2]][1], "\naccuracy: ",out[[2]][2]), "AUC: ", out[[2]][3],)
How can I adapt the annotate command to a plot with several ROC objects?
The label
argument to annotate()
takes a vector of string labels. You can give it the AUCs of the ROC curves:
library(pROC)
roclist <- roc(outcome ~ ndka + wfns + s100b, data=aSAH)
library(ggplot2)
ggroc(roc.list) + annotate("text",
label=sprintf("AUC: %.2f", lapply(roclist, auc)),
x=0.5,
y=c(0.5, 0.4, 0.3))
I am not aware that one can map colors to annotations. For that you'd need to use aes_text()
directly. The name
column will be used for the coloring, so make sure it matches the ROC curves:
# Build an annotation dataset with the "name" column
annot <- data.frame(
label = sprintf("AUC: %.2f", lapply(roclist, auc)),
x = 0.5,
y = seq(from=0.5, along.with=roclist, by=-.1),
name = names(roclist))
ggroc(roc.list) + geom_text(aes(x=x, y=y, label=label), data=annot)