[R] ROCR: auc and logarithm plot
tobias.sing at gmail.com
Tue May 12 14:22:04 CEST 2009
To color the error bars in ROCR the same way as the performance curve,
you need to add one more argument (plotCI.col='red') to your plot
plot( perf2,avg="threshold",lty=2,col=2, spread.estimate="stddev", plotCI.col=2)
The use of 'plotCI.col' is an example for the general mechanism of
ROCR to propagate arguments to the components of a plot (also
explained in ?plot.performance):
Optional graphical parameters to adjust different components of the performance
plot. Parameters are directed to their target component by prefixing them with
the name of the component (component.parameter, e.g. text.cex).
The following components are available: xaxis, yaxis, coloraxis, box
(around the plotting region), points, text, plotCI (error bars), boxplot.
The names of these components are influenced by the R functions that are used
to create them. Thus, par(component) can be used to see which parameters
are available for a given component (with the expection of the three axes;
use par(axis) here). To adjust the canvas or the performance curve(s), the
standard plot parameters can be used without any prefix.
On Tue, May 12, 2009 at 1:48 PM, Tim <timlee126 at yahoo.com> wrote:
> Thanks Tobias!
> A new question: if I want to draw an average ROC from cross-validation, how
> to make the bar color same as the line color? Here is my code:
> "plot( perf2,avg="threshold",lty=2,col=2,
> Even I specify "barcol=2", the color of bars are still black, the default
> one, instead of red "2".
> --- On Tue, 5/12/09, Tobias Sing <tobias.sing at gmail.com> wrote:
> From: Tobias Sing <tobias.sing at gmail.com>
> Subject: Re: [R] ROCR: auc and logarithm plot
> To: timlee126 at yahoo.com, r-help at r-project.org
> Date: Tuesday, May 12, 2009, 5:54 AM
>> 1. I have tried to understand how to extract area-under-curve value by
> looking at the ROCR document and
> googling. Still I am not sure if I am doing the
> right thing. Here is my code, is "auc1" the auc value?
>> pred1 <- prediction(resp1,label1)
>> perf1 <- performance(pred1,"tpr","fpr")
>> plot( perf1, type="l",col=1 )
>> auc1 <- performance(pred1,"auc")
>> auc1 <- auc1 at y.values[]
> If you have only one set of predictions and matching class labels, it
> would be in auc1 at y.values[].
> If you have multiple sets (as from cross-validation or bootstrapping),
> the AUCs would be in auc1 at y.values[], auc1 at y.values[], etc.
> You can collect all of them for example by unlist(perf at y.values).
> Btw, you can use str(auc1) to see the structure of objects.
>> 2. I have to compare two models that have very close ROCs. I'd like to
> have a more distinguishable plot of the ROCs. So is it possible to have a
> logarithm FP axis which might probably separate
> them well? Or zoom in the part
> close to the leftup corner of ROC plot? Or any other ways to make the ROCs
> To "zoom in" to a specific part:
> plot(perf1, xlim=c(0,0.2), ylim=c(0.7,1))
> plot(perf2, add=TRUE, lty=2, col='red')
> If you want logarithmic axes (though I wouldn't personally do this for
> a ROC plot), you can set up an empty canvas and add ROC curves to it:
> plot(1,1, log='x', xlim=c(0.001,1), ylim=c(0,1), type='n')
> plot(perf, add=TRUE)
> You can adjust all components of the performance plots. See
> ?plot.performance and the examples in this slide deck:
> Hope that helps,
More information about the R-help