Description Usage Arguments Details Value Note Author(s) References See Also Examples
package for roc curve plot with ggplot2
| 1 | 
| data | |
| bin | |
| roccol | |
| sp | |
| output | 
none
data frame
none
Honglong Wu
none
none
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.
## The function is currently defined as
function (data = data, bin = 0.01, roccol = "green", sp = 19, 
    output = "roc.pdf") 
{
    pn <- nrow(subset(data, data[, 2] == 1))
    fn <- nrow(data) - pn
    diag = data.frame(x = seq(0, 1, by = bin), y = seq(0, 1, 
        by = bin))
    cutoffs <- seq(0, 1, by = bin)
    x = 0
    y = 0
    for (i in cutoffs) {
        tpn <- nrow(subset(data, data[, 1] >= i & data[, 2] == 
            1))
        fpn <- nrow(subset(data, data[, 1] >= i & data[, 2] == 
            0))
        fnn <- pn - tpn
        tnn <- fn - fpn
        tpr <- tpn/(tpn + fnn)
        fpr <- fpn/(fpn + tnn)
        x <- c(x, fpr)
        y <- c(y, tpr)
    }
    rocdata <- data.frame(FPR = x, TPR = y)
    p <- ggplot(data = rocdata, aes(x = FPR, y = TPR)) + geom_point(color = roccol) + 
        geom_line(color = roccol) + geom_line(data = diag, aes(x = x, 
        y = y), color = "red")
    f <- p + geom_point(data = diag, aes(x = x, y = y), color = "red", 
        shape = sp) + theme(axis.text = element_text(size = 16), 
        title = element_text(size = 18)) + labs(x = "False Positive Rate", 
        y = "True Positive Rate", title = "ROC curve")
    ggsave(f, filename = output, width = 8, height = 6, units = c("in"))
  }
 | 
Loading required package: ggplot2
function (data = data, bin = 0.01, roccol = "green", sp = 19, 
    output = "roc.pdf") 
{
    pn <- nrow(subset(data, data[, 2] == 1))
    fn <- nrow(data) - pn
    diag = data.frame(x = seq(0, 1, by = bin), y = seq(0, 1, 
        by = bin))
    cutoffs <- seq(0, 1, by = bin)
    x = 0
    y = 0
    for (i in cutoffs) {
        tpn <- nrow(subset(data, data[, 1] >= i & data[, 2] == 
            1))
        fpn <- nrow(subset(data, data[, 1] >= i & data[, 2] == 
            0))
        fnn <- pn - tpn
        tnn <- fn - fpn
        tpr <- tpn/(tpn + fnn)
        fpr <- fpn/(fpn + tnn)
        x <- c(x, fpr)
        y <- c(y, tpr)
    }
    rocdata <- data.frame(FPR = x, TPR = y)
    p <- ggplot(data = rocdata, aes(x = FPR, y = TPR)) + geom_point(color = roccol) + 
        geom_line(color = roccol) + geom_line(data = diag, aes(x = x, 
        y = y), color = "red")
    f <- p + geom_point(data = diag, aes(x = x, y = y), color = "red", 
        shape = sp) + theme(axis.text = element_text(size = 16), 
        title = element_text(size = 18)) + labs(x = "False Positive Rate", 
        y = "True Positive Rate", title = "ROC curve")
    ggsave(f, filename = output, width = 8, height = 6, units = c("in"))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.