作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 ggplot2
从 pRoc
包中的 plot.roc
函数重现 ROC 曲线。
library(mlbench)
library(caret)
data(Sonar)
set.seed(998)
fitControl <- trainControl(method = "repeatedcv",
number = 10,
repeats = 10,
## Estimate class probabilities
classProbs = TRUE,
## Evaluate performance using
## the following function
summaryFunction = twoClassSummary)
gbmGrid <- expand.grid(interaction.depth = c(1, 5, 9),
n.trees = (1:30)*50,
shrinkage = 0.1,
n.minobsinnode = 20)
inTraining <- createDataPartition(Sonar$Class, p = .75, list = FALSE)
training <- Sonar[ inTraining,]
testing <- Sonar[-inTraining,]
set.seed(825)
gbmFit <- train(Class ~ ., data = training,
method = "gbm",
trControl = fitControl,
verbose = FALSE,
tuneGrid = gbmGrid,
## Specify which metric to optimize
metric = "ROC")
gbmFit
probs = predict(gbmFit, newdata = testing, type = "prob")
roc = roc(predictor = probs$M,
response = testing$Class,
levels = c('M','R'),
percent = TRUE)
plot.roc(roc, print.auc = TRUE, col='red')
df = data.frame(Specificity=roc$specificities, Sensitivity=roc$sensitivities)
ggplot(data = df, aes(x = Specificity, y = Sensitivity))+
geom_step(color='red', size=2, direction = "hv")+
scale_x_reverse()+
geom_abline(intercept = 100, slope = 1, color='grey')+
annotate("text", x = 30, y = 20, label = paste0('AUC: ', round(roc$auc,1), '%'), size = 8)+
ylab('Sensitivity (%)')+
xlab('Specificity (%)')
scale_x_reverse()
似乎是问题所在,是否有任何其他方法可以反转 X 轴或更正该图?
最佳答案
您可以使用geom_path
代替geom_step
:
ggplot(data = df, aes(x = Specificity, y = Sensitivity))+
geom_path(colour = 'red', size = 2)+
scale_x_reverse() +
geom_abline(intercept = 100, slope = 1, color='grey')+
annotate("text", x = 30, y = 20, label = paste0('AUC: ', round(roc$auc,1), '%'), size = 8)+
ylab('Sensitivity (%)')+
xlab('Specificity (%)')
关于r - ggplot2:在 ROC 图上使用 scale_x_reverse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37438461/
我正在创建以光栅文件为背景的地理 map 。为了更好地显示,我想将其中一些向侧面翻转(即北指向左侧,而不是向上)。这意味着我必须反转 x 轴(除了翻转 x 和 y),否则数据会显示错误(镜像)。 它适
对于我的图表 ggplot(data=data, x=x, y=y, fill=factor(c)+ geom_path()+geom_errorbar()+ geom_point() 我想绘制
我尝试使用 ggplot2 从 pRoc 包中的 plot.roc 函数重现 ROC 曲线。 library(mlbench) library(caret) data(Sonar) set.seed(
我是一名优秀的程序员,十分优秀!