Is there a simple way to do this? I am trying to make an ROC curve in R that displays marked point corresponding to criterion/cut-off values. This is the code I have in RStudio (below):
library(pROC)
library(randomForest)
library(ggplot2)
NfL <- c(values)
Cstatus <- c(1 or 0 values)
plot(x=NfL, y=Cstatus)
glm.fit=glm(Cstatus ~ NfL, family=binomial)
lines(NfL, glm.fit$fitted.values)
obj <- roc(Cstatus, glm.fit$fitted.values, ci=TRUE, plot=FALSE)
obj$ci
ciobj <- ci.se(obj, specificities=seq(0, 1, l=25))
dat.ci <- data.frame(x = as.numeric(rownames(ciobj)),
lower = ciobj[, 1],
upper = ciobj[, 3])
ggroc(obj, legacy.axes=TRUE, linewidth=1) + labs(x = "1 - Specificity \n AUC=0.9184 \n p=0.0022", y = "Sensitivity") + theme_classic() + geom_abline(slope=1, intercept = 0, linetype = "dashed", alpha=0.7) + coord_equal() +
geom_ribbon(data = dat.ci, aes(x = 1-x, ymin = lower, ymax = upper), fill = "steelblue", alpha=0.2) + ggtitle(capture.output(obj$ci)) + theme(axis.text.x = element_text(color="black", size = 12), axis.text.y = element_text(color="black", size=12),
axis.title.x = element_text(face="bold", size=14), axis.title.y = element_text(face="bold", size=14))
which produces: ROC Curve
I would like it to have marked points like this one: ROC Curve with points
You did not provide example data. Here is one approach using the aSAH
dataset in {pROC}:
library(pROC)
#> Type 'citation("pROC")' for a citation.
#>
#> Attaching package: 'pROC'
#> The following objects are masked from 'package:stats':
#>
#> cov, smooth, var
library(ggplot2)
gg <- roc(aSAH, outcome, s100b) |>
ggroc()
#> Setting levels: control = Good, case = Poor
#> Setting direction: controls < cases
gg +
geom_point(aes(specificity, sensitivity), gg$data)
Created on 2024-04-03 with reprex v2.1.0