The ROC curve is below the oblique line, how to correct it?

Viewed 63

I use ggplot and plotROC packages to draw ROC curves, but one of the drawn curves is in the opposite direction. How can I modify them to keep the two curves in the same direction?

enter image description here

My code is as follows:

library("plotROC")
Response <- c(0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
       0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 
       0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 
       0, 0, 1, 1, 0, 0)
len <- c(4, 7, 8, 10, 4, 10, 10, 10, 10, 10, 9, 8, 7, 7, 5, 4, 4, 4, 3, 3, 2, 
         2, 9, 11, 0.5, 10, 8, 5, 4, 10, 10, 9, 8, 8, 7, 5, 1, 12, 10, 11, 9, 
         10, 7, 10, 7, 12, 10, 11, 10, 4, 12, 7, 12, 14, 10, 9, 9, 7, 10, 2, 
         12, 12, 10, 16, 10, 9, 15, 10, 9, 5, 12, 12, 11, 6, 9.5, 9, 11, 3)
gc <- c(15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
        15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
        13, 12, 12, 11, 10, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 
        7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 4, 3, 3, 3,3)

d1 <- data.frame(Response = Response, Predictor = len, group = "len")
d2 <- data.frame(Response = Response, Predictor = gc, group = "gc")
mydata <- rbind(d1, d2)

ggplot(mydata, aes(d = Response, m = Predictor, color = group, linetype = group, shape = group)) +
  geom_roc(n.cut = 0, show.legend = TRUE, labels=FALSE, size = 0.6)+
  geom_abline(size = 0.7, color = "grey", linetype = "dashed")+
  xlab("1 - Specificity") +
  ylab("Sensitivity") 
0 Answers
Related