2
votes

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))

Output

1
pch selects the point character. Obviously lines doesn’t respond to it. Use points instead.Konrad Rudolph
It says the first argument is a list object, so it does not have components 'x' and 'y'Chris T.
Adding lty = c(2, 3, 4, 1) to the legend will fix the line types in the legendAllan Cameron
@Allan, I have updated that in my edit, thanks for reminding me that.Chris T.
Though there are so many points, it doesn't look good. You might need to do something like points(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

1 Answers

2
votes

Apart from color, there are two things you can change on a line: type (lty) and width (lwd).

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, lwd = 4, col = "grey48")
lines(roc.pred4, type = "l", lty = 4, lwd = 8, 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),
       lwd = c(1, 1, 4, 8, 1))

enter image description here

Besides of that, you'll reach the limits of what you can show on a black and white plot.

If you had fewer points on your ROC curve, I would suggest to use type = "b" which plots points and lines:

data(aSAH)
plot(roc(aSAH$outcome, aSAH$wfns), type = "b")

enter image description here

Then you can play with pch, bg and col on the points too. However as you noticed that's not going to work for you because your curve has too many points.