我制作了4种不同模型的ROC曲线。这是我使用的代码:
auc_model1 <- round(auc(roc_model1), 3)
auc_model2 <- round(auc(roc_model2), 3)
auc_model3 <- round(auc(roc_model3), 3)
auc_model4 <- round(auc(roc_model4), 3)
legend_labels <- c(paste('Model 1 (AUC=', auc_model1, ')'),
paste('Model 2 (AUC=', auc_model2, ')'),
paste('Model 3 (AUC=', auc_model3, ')'),
paste('Model 4 (AUC=', auc_model4, ')'))
data <- data.frame(fpr = roc_model1$specificities, tpr = roc_model1$sensitivities, model = "Model 1")
data <- rbind(data, data.frame(fpr = roc_model2$specificities, tpr = roc_model2$sensitivities, model = "Model 2"))
data <- rbind(data, data.frame(fpr = roc_model3$specificities, tpr = roc_model3$sensitivities, model = "Model 3"))
data <- rbind(data, data.frame(fpr = roc_model4$specificities, tpr = roc_model4$sensitivities, model = "Model 4"))
ggplot(data, aes(x = 1 - fpr, y = tpr, color = model)) +
geom_line(size = 0.8) +
labs(x = "False Positive Rate", y = "True Positive Rate", color = "Model") +
geom_abline(intercept = 0, slope = 1, linetype = "dashed") +
theme_minimal() +
theme(legend.position = "bottomright") +
guides(color = guide_legend(title = NULL, label.position = "bottom", label.hjust = 1, override.aes = list(color = c("blue", "red", "green", "purple")))) +
annotate("text", x = 0.7, y = 0.08, label = paste(legend_labels, collapse = "\n"), hjust = 0, vjust = 0)
这是结果。如果不给图例上色,我不知道哪个型号是哪个: