plot.PRROC {PRROC} | R Documentation |
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 class '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 |
|
xlim |
as in |
ylim |
as in |
auc.main |
|
auc.type |
the area under the curve shown in the title (see also |
legend |
if |
xlab |
the label of the x-axis. If |
ylab |
the label of the y-axis. If |
main |
the title of the plot. If |
color |
if |
lwd |
the line width of the curve |
add |
if |
scale.color |
vector of colors that are used to reflect score thresholds, compare |
max.plot |
if |
min.plot |
if |
rand.plot |
if |
fill.area |
fill the area between maximum and minimum curve (given both have been computed for |
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 |
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
.
Author(s)
Jan Grau and Jens Keilwagen
See Also
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
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" );