ggprroc: Plotting PRROC objects using ggplot2

View source: R/PRROC.R

ggprrocR Documentation

Plotting PRROC objects using ggplot2

Description

Plots the PR or ROC curves of a PRROC object using ggplot2. To obtain such curves, pr.curve or roc.curve must be called with argument curve=TRUE.

Usage

ggprroc(x, auc.main=TRUE, auc.type=c("integral","davis.goadrich"),
    xlab=NULL,ylab=NULL,
    main=NULL,
    max.plot = FALSE, min.plot = FALSE, rand.plot = FALSE,
    fill.area = (max.plot & min.plot))

Arguments

x

a PRROC object obtained from pr.curve or roc.curve

auc.main

TRUE to show the area under curve in the title

auc.type

the area under the curve shown in the title (see also pr.curve). Ignored if auc.main=FALSE or x$type=="ROC".

xlab

the label of the x-axis. If NULL, label is chosen according the kind of the curve.

ylab

the label of the y-axis. If NULL, label is chosen according the kind of the curve.

main

the title of the plot. If NULL, title is chosen according the kind of the curve.

max.plot

if TRUE and x has been computed including the maximum curve, plot this maximum curve

min.plot

if TRUE and x has been computed including the minimum curve, plot this maximum curve

rand.plot

if TRUE and x has been computed including the curve of a random classifier, plot this curve

fill.area

fill the area between maximum and minimum curve (given both have been computed for x) (ignored if add=TRUE)

Details

This function plots PRROC objects as a curve using ggplot2, specifically geom_line. If minimum, maximum or random curves have been computed, these can be added to the plot.

The function returns a ggplot2 object that may be further modified using themes, scales on the colours, etc.

Author(s)

Jan Grau and Jens Keilwagen

See Also

pr.curve

roc.curve

Examples

# create artificial scores as random numbers
x <- rnorm( 1000 );
y <- rnorm( 1000, -1 );

# compute PR curve
pr <- pr.curve( x, y, curve = TRUE );

# standard plot of PR curve
ggprroc( pr );

# compute ROC curve
roc <- roc.curve( x, y, curve = TRUE );

# standard plot of ROC curve
ggprroc( roc );


# include maximum, minimum and random curves
pr <- pr.curve( x, y, curve = TRUE, max.compute = TRUE, 
    min.compute = TRUE, rand.compute = TRUE );
    
ggprroc( pr, max.plot = TRUE, min.plot = TRUE, rand.plot = TRUE )


# modify theme and colour scale

pl <- ggprroc( pr, max.plot = TRUE, min.plot = TRUE, rand.plot = TRUE )


if(require(ggplot2)){
  pl + scale_color_viridis_c(option="D",name="Some score") +
      xlab("Sensitivity")+
      theme_gray()
}


PRROC documentation built on April 12, 2025, 1:46 a.m.