ggplot2 - R ggplot add new roc curve -
i want add roc curve ggplot chart, returns error code.
library(ggplot2) library(plotroc) set.seed(2529) d.ex <- rbinom(200, size = 1, prob = .5) m1 <- rnorm(200, mean = d.ex, sd = .65) m2 <- rnorm(200, mean = d.ex, sd = 1.5) test <- data.frame(d = d.ex, d.str = c("healthy", "ill")[d.ex + 1], m1 = m1, m2 = m2, stringsasfactors = false) plot<-ggplot(longtest, aes(d = d, m = m1 )) + geom_roc() + style_roc() plot
its ok, if im add new roc line return error
plot<-ggplot(longtest, aes(d = d, m = m1 )) + geom_roc() + style_roc() plot+ggplot(test, aes(d = d, m = m2)) + geom_roc()
error in p + o : non-numeric argument binary operator in addition: warning message: incompatible methods ("+.gg", "ops.data.frame") "+"
how can add new line , color line different color,and add legend
melt data frame wide long format, map variable name line color within aesthetics mappings:
ggplot(melt_roc(test, "d", c("m1", "m2")), aes(d = d, m = m, color = name)) + geom_roc() + style_roc()
you this, if want:
ggplot() + geom_roc(aes(d = d, m = m1, color="roc1"), test) + geom_roc(aes(d = d, m = m2, color="roc2"), test) + scale_color_manual(values=c("roc1"="red", "roc2"="blue"), name="color legend", guide="legend") + style_roc()
Comments
Post a Comment