I have a binomial logit model and I am evaluating the goodness of fit of my model using the ROC curve :
library(pROC)
curva_ROC <- roc(modelo_logit_viv$y,modelo_logit_viv$fitted.values)
plot(curva_ROC,col = "blue",xlim = c(1,0),ylim = c(0,1),
xlab = "Especifidad", ylab ="Sensibilidad", main = "Curva de ROC")
auc(curva_ROC) # 0.8445
This is the graph that returns me:
I want to modify it as follows:
Delimit the x-axis (specificity) in such a way that the beginning is almost at 1 and ends at 0, that is, that the limits of the horizontal axis coincide with the diagonal (I thought that by indicating I
xlab = c(0,1)
would obtain that result, but the graph does not vary when include this argument in the plot function).That the area between the curve and the diagonal is colored in a lighter blue than the curve.
That the value of the area appears
auc(curva_ROC)
right in the center of said area.
1. Adjust axes
The way to do it in the base plots is through the parameters
xlim
andylim
I couldn't verify it with your data, but it works properly with the example I put together for this answer. On the other handxlab
, theyylab
only establish the "labels" or labels of each axis2. Color area
The behavior of
plot.ROC()
supports coloring the entire area of the curve, using these parameters (example):What you are looking for, however, is to color the curve all the way to the diagonal. One way could be to generate the polygon below the curve and up to the diagonal, taking advantage of the data of the
plot.ROC()
3. Text with AUC value
You can configure and adjust it with the following parameters:
The values of
x
ey
should be adjusted so that the text fits inside the area.Example
Result:
Sources: