Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggroc with several line colors #74

Closed
ProfBiscuit opened this issue Feb 27, 2020 · 4 comments
Closed

ggroc with several line colors #74

ProfBiscuit opened this issue Feb 27, 2020 · 4 comments

Comments

@ProfBiscuit
Copy link

ProfBiscuit commented Feb 27, 2020

Hello,

I am using your amazing package to plot multiple ROC curves on the same axis. What I am attempting to do is plot, say, 5 ROC curves that are one color and a sixth ROC curve that is red.

I understand that this topic has been raised before ( #issue #42 ) however, I do not understand how the code modification you pushed addressed this request.

For example, if I was plotting 5 curves, would it be doable for 'color' to be fed a list of length 5 such as 'colour = c(rep('grey', 4), 'red')?

My exact scenario is similar to this, although in my real-world situation the models are far more informative (I hope).

library(pROC)
library(dplyr)
library(purrr)

df <- data.frame(
  truth = rbinom(n = 1000, size = 1, prob = 0.5),
  pred.prob = runif(n = 1000),
  group = factor(rep(LETTERS[1:5], times = 200))
)

df.list <- df %>% 
  group_split(group)

map_function <- function(x){
  pROC::roc(
    data = x,
    response = truth,
    predictor = pred.prob
  )
}

roc.list <- map(df.list, map_function)

ggroc(roc.list, color = "grey", alpha = 0.5) +
  ggplot2::theme_bw()

Given how your package is currently written, how could this be accomplished?

Thanks!

@xrobin
Copy link
Owner

xrobin commented Feb 28, 2020

Quick answer, don't have time to look at it in much detail now.
Issue #42 is implicitly about using automatic mapping of several aesthetics, which is irrelevant to you.
So you should leave it empty or maybe set it to "group" (I can't remember what's the default right now) and define a vector of colors as you proposed. I believe these should be passed to geom_line, although I can't remember testing it.

@ProfBiscuit
Copy link
Author

Ah, sure. scale_color_manual seems to do the job.

library(pROC)
library(dplyr)
library(purrr)
library(ggplot2)

df <- data.frame(
  truth = rbinom(n = 1000, size = 1, prob = 0.5),
  pred.prob = runif(n = 1000),
  group = factor(rep(LETTERS[1:5], times = 200))
)

df.list <- df %>% 
  group_split(group)

map_function <- function(x){
  pROC::roc(
    data = x,
    response = truth,
    predictor = pred.prob
  )
}

roc.list <- map(df.list, map_function)

ggroc(roc.list, alpha = 0.5) +
  scale_color_manual(values=c(rep('grey', 4), 'red')) + 
  theme_bw()

image

Thank you!

@ProfBiscuit ProfBiscuit changed the title ggroc with several aesthetics ggroc with several line colors Feb 28, 2020
@xrobin
Copy link
Owner

xrobin commented Feb 28, 2020

Oh that shouldn't be necessary. I don't remember having to use that with geom_line...
Or if it is it should be at least documented / mentioned. I'm reopening the issue and will look into it soon.

@xrobin
Copy link
Owner

xrobin commented Mar 1, 2020

Of course one can't pass a vector of colors to geom_lines, I'm not sure why I thought it would be doable.
Indeed you need to use one of the scale_color_* function as you would to change colors in general with ggplot2. And make sure you map the aesthetic, so aes="color" is needed.
I've updated the documentation with an example. It always takes me too much time to figure out how to customize a ggplot2 plot so an example can't hurt.
Thanks for bringing this issue to my knowledge!

@xrobin xrobin closed this as completed Mar 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants