I am trying to use the code below to plot many ROC plots on one plot. x
is a list of vectors (each containing x-coordinates) and y
is a list vectors (each containing y-coordinates).
plotROC<- function(x, y, label=NA) {
p <- ggplot() + ggtitle("ROC Plot") + xlab("False Positive Rate") +
ylab("True Positive Rate") + xlim(c(0,1)) + ylim(c(0, 1)) +
geom_segment(aes(x=0, y=0, xend=1, yend=1), colour="black")
for (i in 1:length(x)) {
auc <- AUC(x[[i]], y[[i]])
lab <- ifelse(is.na(label[i]), "", paste(label[i], "\n", sep=""))
p <- p + geom_line(
aes(x[[i]], y[[i]], colour=paste(lab, "AUC: ",
formatC(auc, format="f",
digits=2), sep="")))
}
p + scale_color_brewer(palette=palette) +
theme(legend.title=element_blank())
}
For some reason the the function only plots the final ROC plot. If anybody could help I would be very appreciative!
Thanks,
Jack