我try 使用以下代码绘制ROC曲线:
library(titanic)
library(pROC)
library(ggplot2)
r <- roc(Survived ~ Fare, data = titanic_train)
#AUC text
auc <- auc(r)
ci <- ci.auc(r)
ci_l <- round(ci[1], 2)
ci_u <- round(ci[3], 2)
legend_text <- paste0("AUC = ", round(auc, 2), " (95% CI = ", ci_l, " - ", ci_u, ")")
#Plot
p <- ggroc(r) +
scale_x_reverse() +
labs(
title="ROC",
y = "Sensitivity",
x = "1 - Specificity"
) +
geom_segment(aes(x=1, xend=0, y=0, yend=1), color="grey", linetype="dashed") +
annotate("text", x = 0.3, y = 0.05, label = legend_text)
print(p)
但是,当我收到这样的错误消息时,"Scale_x_Reverse"出现了问题:"已经存在x的比例. 为x添加另一个刻度,它将取代现有的刻度.
我希望X轴从0到1(因此将当前的1恢复到0).
对如何解决这个问题有什么 idea 吗?我不知道为什么它不起作用.