1

I'm trying to combine multiple ROC value into one graph, so far I already managed to do that. However, I'm having a hard time changing the legend.

roc.list <- list(roc_obj,roc_objL,roc_objR)

ggroc(roc.list, aes = c("linetype"),legacy.axes = TRUE) + 
              labs(x = "1 - Specificity", y = "Sensitivity") + theme_classic() +geom_abline()

ROC Curve

I can't manage to change the "main" and "1", "2", "3".

I tried adding the

labs(x = "1 - Specificity", y = "Sensitivity", fill = c("Mean Gonial", "Gonial Angle Left","Gonial Angle Right")) + theme_classic() +geom_abline()

I expect the output image legend main title to be "Gonial Angle Measurement" and "Mean Gonial Angle", "Gonial Angle Left", "Gonial Angle Right" to 1, 2, and 3 legends, respectively.

Thank you

  • Welcome to stack overflow Rizky. In order to improve the quality of your question, you should provide a minimal reproducible example that everyone can run directly, as explained in https://stackoverflow.com/questions/5963269 . This would disambiguate which package you are using, as neither R nor ggplot 2 have a ggroc function... but several other packages do, such as ggROC or pROC. Without the full code you are using we can only guess which one you used, so you will get lower quality answers. – Calimo Aug 22 '19 at 17:27
  • Thank you for the feedback, Calimo. I will try to edit the question. – Rizky Merdietio Aug 23 '19 at 15:51

2 Answers2

0

You can add the title with ggtitle and play a little bit around wih your list of curves to do the rest:

library(pROC)
library(ggplot2)

# Create a basic roc object
data(aSAH)
rocobj1 <- roc(aSAH$outcome, aSAH$s100b)
rocobj2 <- roc(aSAH$outcome, aSAH$wfns)
rocobj3 <- roc(aSAH$outcome, aSAH$ndka)
roclist <- list("First ROC" = rocobj1,
                "Second ROC" = rocobj2,
                "Third ROC" = rocobj3)

g <- ggroc(roclist, aes = "linetype", legacy.axes = TRUE) +
  geom_abline() +
  theme_classic() +
  ggtitle("The new title") +
  labs(x = "1 - Specificity",
       y = "Sensitivity",
       linetype = "Different legend title")
g

ROC curves

Vincent Guillemot
  • 3,394
  • 14
  • 21
  • 1
    You should clarify that the actual answer to the OP is in the way you fill `roclist`. The `ggtitle` bit is nice to have, but not what was actually asked. – Calimo Aug 22 '19 at 17:29
  • Thank you for the feedback, I will use it next time I asked a question and helping others if needed. – Rizky Merdietio Aug 24 '19 at 03:21
0

First time I answer here. You can (1) name the list elements the way you want or (2) add

scale_linetype_discrete(labels=c("Mean Gonial","Gonial Angle Left","Gonial Angle Right"))

For the legend title you need to address the right legend. In your case linetype, not fill.

labs(x = "1 - Specificity", y = "Sensitivity", linetype="Gonial Angle Measurement"))

I think this code will help you

library(pROC)
library(ggplot2)

roc.list <- roc(outcome ~ s100b + ndka + wfns, data = aSAH)
g.list <- ggroc(roc.list)

ggroc(roc.list, aes = c("linetype"), legacy.axes = TRUE)+ 
  labs(x = "1 - Specificity", y = "Sensitivity", linetype="Gonial Angle Measurement") + 
  scale_linetype_discrete(labels=c("Mean Gonial","Gonial Angle Left","Gonial Angle Right"))+
  theme_classic() +
  geom_abline()
  • 1
    Welcome Johannes. You could improve your answer by providing full example code that are runnable. In particular you seem to have an odd number of round brackets in pretty much every of your code blocks. You would have noticed that if you hadn't isolated bits of the code only. – Calimo Aug 22 '19 at 17:24
  • thanks for the feed back. is it better after with the edit? – Johannes Stötzer Aug 22 '19 at 18:24
  • If I run your code I get an error: Error in roc(outcome ~ s100b + ndka + wfns, data = aSAH) : could not find function "roc" – Calimo Sep 01 '19 at 06:06
  • Also you could provide an example how to implement option (1). And no need to flag your edits with "EDIT" on this site: integrate them to your answer as well as you can (questions and answers have a history if anyone wants to see what changed). – Calimo Sep 01 '19 at 06:13