简体   繁体   English

在 R 中更改 ROC 上的刻度线

[英]Change tick marks on ROC in R

library(ROCR)
data(ROCR.simple)
pred = prediction( ROCR.simple$predictions, ROCR.simple$labels)
roc.perf = performance(pred, measure = "tpr", x.measure = "fpr")
plot(roc.perf)

How can I change the scale of the x and y axis to be a percent instead of decimal?如何将 x 和 y 轴的比例更改为百分比而不是小数?

Note: I would like to use a base R solution, or use a solution available in the ROCR package.注意:我想使用基本的 R 解决方案,或者使用 ROCR 包中提供的解决方案。 I am unable to access the GGPLOT2 library, since I am on a closed network.我无法访问 GGPLOT2 库,因为我在一个封闭的网络上。

If you look at the code for .plot.performance (which is used to plot your prediction), they store the x and y values under @x.values and @y.values.如果您查看.plot.performance的代码(用于绘制您的预测),它们会将 x 和 y 值存储在 @x.values 和 @y.values 下。

So you can do it like this:所以你可以这样做:

plot(roc.perf@x.values[[1]]*100,roc.perf@y.values[[1]]*100)

To get % as ticks, do:要获得 % 作为刻度,请执行以下操作:

plot(roc.perf@x.values[[1]],roc.perf@y.values[[1]],
xaxt="n",yaxt="n",type="l",ylab="True Positive Rate",
xlab="False Positive Rate")

TICKS=seq(0,1,by=0.2)
LABELS=paste0(100*TICKS,"%")
axis(side=2,at=TICKS,label=LABELS)
axis(side=1,at=TICKS,label=LABELS)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM