I want to plot ROC curves for 5 estimated models using R's pROC
application. Because I'm using gray scales, which may look indistinguishable visually, so I want to accentuate different line types by assigning different pch
to different ROC curves, however, I found the lines()
function is quite unresponsive to pch
options.
Also, when I want to label their respective AUC values, using the print.auc
option, beyond the default model (Model 1), the roc()
and lines()
functions do seem to work. Only AUC value for the first model is shown.
It will be very appreciated if someone could point me toward some feasible ways to achieve the desired result. Below is my current code for the plot and output.
### load the data ###
library(readxl)
dataURL <- "https://www.dropbox.com/s/vri9fx2xa1pfj7w/predict.xlsx?dl=1"
temp = tempfile(fileext = ".xlsx")
download.file(dataURL, destfile=temp, mode='wb')
predict <- readxl::read_excel(temp, sheet =1)
### plotting and labelling ###
library(pROC)
roc.pred2 <- roc(predict$IAC, predict$phat2, percent = TRUE, main = "Smoothing")
roc.pred3 <- roc(predict$IAC, predict$phat3, percent = TRUE, main = "Smoothing")
roc.pred4 <- roc(predict$IAC, predict$phat4, percent = TRUE, main = "Smoothing")
roc.pred5 <- roc(predict$IAC, predict$phat5, percent = TRUE, main = "Smoothing")
plot.roc(predict$IAC, predict$phat1, percent = TRUE, main = "ROC curves", add = FALSE, asp = NA, print.auc = TRUE)
lines(roc.pred2, type = "l", lty = 2, col = "grey35")
lines(roc.pred3, type = "l", lty = 3, col = "grey48")
lines(roc.pred4, type = "l", lty = 4, col = "grey61")
lines(roc.pred5, type = "l", lty = 1, pch = 24, col = "grey76")
legend("bottomright",
legend = c("Model 1", "Model 2", "Model 3", "Model 4", "Model 5"),
col = c("black", "grey35", "grey48", "grey61", "grey76"),
lty = c(1, 2, 3, 4, 1))
pch
selects the point character. Obviouslylines
doesn’t respond to it. Usepoints
instead. – Konrad Rudolphdoes not have components 'x' and 'y'
– Chris T.lty = c(2, 3, 4, 1)
to the legend will fix the line types in the legend – Allan Cameronpoints(roc.pred2$specificities[seq(1, length(roc.pred2$sensitivities), 100)],roc.pred2$sensitivities[seq(1, length(roc.pred2$sensitivities), 100)] )
so that only every hundredth point is plotted. – Allan Cameron