plot_roc: Reicever Operating Characteristic Curve(s)

View source: R/plot_roc.R

plot_rocR Documentation

Reicever Operating Characteristic Curve(s)

Description

This functions plots ROC curves for one or several classifiers.

Usage

plot_roc(
  obs,
  pred,
  pal_curves = "npg",
  title = ifelse(is.numeric(pred), "ROC Curve", "ROC Curves"),
  leg.txt = NULL,
  legend = "bottomright",
  hover = FALSE
)

Arguments

obs

Vector of observed outcomes. Must be dichotomous. Can be logical, numeric, character, or factor. If numeric, obs must be coded 1 or 0. If character or factor, a warning will be issued clarifying that the first level is assumed to be the reference.

pred

Vector of predicted values, or several such vectors organized into a data frame or list, optionally named. Must be numeric. Common examples include the probabilities output by a logistic model, or the expression levels of a particular biomarker.

pal_curves

String specifying the color palette to use when plotting multiple vectors. Options include "ggplot", all qualitative color schemes available in RColorBrewer, and the complete collection of ggsci palettes. Alternatively, a character vector of colors with length equal to the number of vectors in dat.

title

Optional plot title.

leg.txt

Optional legend title.

legend

Legend position. Must be one of "bottom", "left", "top", "right", "bottomright", "bottomleft", "topleft", or "topright".

hover

Show predictor name by hovering mouse over ROC curve? If TRUE, the plot is rendered in HTML and will either open in your browser's graphic display or appear in the RStudio viewer.

Details

ROC curves plot the false positive rate (i.e., 1 - specificity) against the true positive rate (i.e., sensitivity) for a given classifier and vector of observations. The area under the ROC curve (AUC) is a common performance metric for binary classifiers. The grey diagonal line across the plot represents the performance of a theoretical random classifier.

Examples

y <- rbinom(1000, size = 1, prob = 0.5)
x1 <- rnorm(1000, mean = y)
plot_roc(obs = y, pred = x1)

x2 <- rnorm(1000, mean = y, sd = 2)
plot_roc(obs = y, pred = list("Better" = x1, "Worse" = x2))


dswatson/bioplotr documentation built on March 3, 2023, 9:43 p.m.