Learn R Programming

PRROC (version 1.3.1)

plot.PRROC: Plotting PRROC objects

Description

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

Usage

# S3 method for PRROC
plot(x, xlim=c(0,1), ylim=c(0,1), auc.main=TRUE, 
    auc.type=c("integral","davis.goadrich"), 
    legend=ifelse(is.logical(color) & color==TRUE,4,NA), xlab=NULL, ylab=NULL, 
    main=NULL, color=TRUE, lwd=3, add=FALSE, 
    scale.color=hsv(h=seq(0,1,length=100)*0.8, s=1, v=1), 
    max.plot = FALSE, min.plot = FALSE, rand.plot = FALSE, 
    fill.area = (max.plot & min.plot), maxminrand.col = grey(0.5), 
    fill.color = grey(0.95), ...)

Arguments

x

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

xlim

as in plot

ylim

as in plot

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".

legend

if TRUE (and color==TRUE), a legend for the color scheme for the scores is shown on the right side of the main plot. If legend is a number between 1 and 4, the legend is drawn on the correspond side of the main plot (see axis). If legend is FALSE or NA, no legend is drawn.

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.

color

if TRUE, curve is plotted in colors reflecting score thresholds, if FALSE, the curve is plotted in black, if a color value (e.g., 2 or "red" for red) the curve is plotted in that color. For everything different from TRUE, the legend is omitted irrespective of the value of argument legend

lwd

the line width of the curve

add

if TRUE, the curve is added to an existing plot. Only works correctly, if in the previous call (with add==FALSE), no legend has been added to the plot.

scale.color

vector of colors that are used to reflect score thresholds, compare color

max.plot

if TRUE and x has been computed including the maximum curve, plot this maximum curve (ignored if add=TRUE)

min.plot

if TRUE and x has been computed including the minimum curve, plot this maximum curve (ignored if add=TRUE)

rand.plot

if TRUE and x has been computed including the curve of a random classifier, plot this curve (ignored if add=TRUE)

fill.area

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

maxminrand.col

the plot color for the maximum, minimum, and random curves

fill.color

the fill color for the area between minimum and maximum curve

see plot

Details

The plot method for PRROC objects can be used in different ways.

The first is to plot a visualization of a single ROC or PR curve that also represents the classification thresholds of individual points on the curve by a color scale. In this case, a PRROC object must be provided as x, add must be FALSE, and color must be TRUE. If, in addition, legend is set to TRUE, a legend translating colors to numerical threshold values is included to the right of the curve plot itself. The layout of curve plot and legend is accomplished using layout(), which means that this type of ROC/PR plot cannot be combined with other/complex layouts.

The second application of the plot method is to compare the performance of different classifiers (typically on the same data set). To do so, plot must be called with add=FALSE and color set to one specific color (e.g., 2, "red",...) for the first PRROC object provided as x. Subsequent calls of plot with add=TRUE can be used to add further curves to the first plot, where different colors may be specified by the color parameter.

In both cases, the first (or only) call to plot also allows for including plots of the maximum and minimum curve, highlighting the area between minimum and maximum, and the curve of a random classifier. For this purpose, the PRROC object needs to be created (using pr.curve or roc.curve) with the corresponding parameters (e.g., max.compute) set to TRUE.

Additional examples for the different use cases and corresponding plot commands are given in the documentations of pr.curve and roc.curve.

See Also

pr.curve

roc.curve

Examples

Run this code
# NOT RUN {
# 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
plot( pr );

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

# standard plot of ROC curve
plot( roc );

# create another set of scores
x.2 <- rnorm( 1000 );
y.2 <- rnorm( 1000, -2 );

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

# plot PR curve in red, without legend
plot( pr, color = "red", auc.main=FALSE );
# add second PR curve in green
plot( pr.2, color = 3, add = TRUE );


# plot ROC curve in red, without legend
plot( roc, color = "red", auc.main=FALSE);
# add second ROC curve in green
plot( roc.2, color = 3, add = TRUE );

# plot PR curve with legend below the main plot
plot( pr, legend=1 );

# compute PR curve with minimum and maximum curve, and random classifier
pr <- pr.curve( x, y, curve = TRUE, max.compute = TRUE, 
  min.compute = TRUE, rand.compute = TRUE);

# plot PR curve with area between minimum and 
# maximum curve in green and random classifier in blue
plot(pr, rand.plot = TRUE, fill.area = TRUE, fill.color = rgb(0.8,1,0.8), 
  maxminrand.col = "blue" );


# }

Run the code above in your browser using DataLab