Skip to content

Instantly share code, notes, and snippets.

@sachsmc
Created February 25, 2016 21:45
Show Gist options
  • Save sachsmc/5f7d110782e57d711882 to your computer and use it in GitHub Desktop.
Save sachsmc/5f7d110782e57d711882 to your computer and use it in GitHub Desktop.
Workaround to plot labels at precise points using plotROC
library(plotROC)
D <- rbinom(100, 1, .4)
fkd <- data.frame(D = D, Y = rnorm(100, mean = D, sd = .5))
p1 <- ggplot(fkd, aes(d = D, m = Y)) + geom_roc(n.cuts = 0)
dat <- ggplot_build(p1)$data[[1]]
mycut.i <- c(10, 50, 90) # find the indices of the labels you want to plot in dat above
p1 + geom_point(data = dat[mycut.i, ],
aes(d = NULL, m = NULL, x = x, y = y)) +
geom_text(data = dat[mycut.i, ],
aes(d = NULL, m = NULL, x = x - .03, y = y + .03, label = round(cutoffs, 1)))
p1 + geom_point(data = dat[mycut.i, ],
aes(d = NULL, m = NULL, x = x, y = y)) +
geom_label(data = dat[mycut.i, ],
aes(d = NULL, m = NULL, x = x - .03, y = y + .03, label = round(cutoffs, 1)))
@sachsmc
Copy link
Author

sachsmc commented Feb 25, 2016

rplot01
rplot02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment