diff --git a/R/ggroc.R b/R/ggroc.R index 3f12951..9ce945c 100644 --- a/R/ggroc.R +++ b/R/ggroc.R @@ -5,28 +5,34 @@ get.coords.for.ggplot <- function(roc) { return(df[rev(seq(nrow(df))),]) } -get.aes.for.ggplot <- function(roc, legacy.axes) { +get.aes.for.ggplot <- function(roc, legacy.axes, extra_aes) { # Prepare the aesthetics if(roc$percent) { if (legacy.axes) { - aes <- ggplot2::aes_string(x = "1-specificity", y = "sensitivity") + aes_list <- list(x = "1-specificity", y = "sensitivity") xlims <- ggplot2::scale_x_continuous(lim=c(0, 100)) } else { - aes <- ggplot2::aes_string(x = "specificity", y = "sensitivity") + aes_list <- list(x = "specificity", y = "sensitivity") xlims <- ggplot2::scale_x_reverse(lim=c(100, 0)) } } else { if (legacy.axes) { - aes <- ggplot2::aes_string(x = "1-specificity", y = "sensitivity") + aes_list <- list(x = "1-specificity", y = "sensitivity") xlims <- ggplot2::scale_x_continuous(lim=c(0, 1)) } else { - aes <- ggplot2::aes_string(x = "specificity", y = "sensitivity") + aes_list <- list(x = "specificity", y = "sensitivity") xlims <- ggplot2::scale_x_reverse(lim=c(1, 0)) } } + # Add extra aes + for (ae in extra_aes) { + aes_list[[ae]] <- "name" + } + aes <- do.call(ggplot2::aes_string, aes_list) + return(list(aes=aes, xlims=xlims)) } @@ -49,8 +55,12 @@ ggroc.roc <- function(data, legacy.axes = FALSE, ...) { } ggroc.list <- function(data, aes = c("colour", "alpha", "linetype", "size", "group"), legacy.axes = FALSE, ...) { - aes <- match.arg(aes) - + if (missing(aes)) { + aes <- "colour" + } + aes <- sub("color", "colour", aes) + aes <- match.arg(aes, several.ok = TRUE) + # Make sure data is a list and every element is a roc object if (! all(sapply(data, is, "roc"))) { stop("All elements in 'data' must be 'roc' objects.") @@ -83,8 +93,7 @@ ggroc.list <- function(data, aes = c("colour", "alpha", "linetype", "size", "gro coord.dfs <- do.call(rbind, coord.dfs) # Prepare the aesthetics - aes.ggplot <- get.aes.for.ggplot(data[[1]], legacy.axes) - aes.ggplot$aes[[aes]] <- as.symbol("name") + aes.ggplot <- get.aes.for.ggplot(data[[1]], legacy.axes, aes) # Do the plotting ggplot(coord.dfs, aes.ggplot$aes) + ggplot2::geom_line(...) + aes.ggplot$xlims diff --git a/man/ggroc.Rd b/man/ggroc.Rd index baaaba1..d62d19d 100644 --- a/man/ggroc.Rd +++ b/man/ggroc.Rd @@ -19,7 +19,7 @@ \arguments{ \item{data}{a roc object from the \link{roc} function, or a list of roc objects. } - \item{aes}{the name of the aesthetics for \code{\link{geom_line}} to map to the different ROC curves supplied. Use \dQuote{group} if + \item{aes}{the name(s) of the aesthetics for \code{\link{geom_line}} to map to the different ROC curves supplied. Use \dQuote{group} if you want the curves to appear with the same aestetic, for instance if you are faceting instead.} \item{legacy.axes}{a logical indicating if the specificity axis (x axis) must be plotted as as decreasing \dQuote{specificity} @@ -74,6 +74,9 @@ g3 <- ggroc(roc.list, linetype=2) g3 g4 <- ggroc(roc.list, aes="linetype", color="red") g4 +# changing multiple aesthetics: +g5 <- ggroc(roc.list, aes=c("linetype", "color")) +g5 # OR faceting g.list + facet_grid(.~name) + theme(legend.position="none")