Changing scale of the ROC chart
Asked Answered
H

2

7

I am using the following code to plot the ROC curve after having run the logistic regression.

fit1 <- glm(formula=GB160M3~Behvscore, data=eflscr,family="binomial", na.action = na.exclude)
prob1=predict(fit1, type=c("response"))
eflscr$prob1 = prob1

library(pROC)
g1 <- roc(GB160M3~prob1, data=eflscr, plot=TRUE,  grid=TRUE, print.auc=TRUE)

The ROC curves plotted look like this (see link below)

enter image description here

  1. The x-axis scale does not fill the who chart.
  2. How can I change the x axis to report 1 - specifically?
Humiliating answered 9/12, 2016 at 9:17 Comment(1)
Note that question 1 is addressed in more details specifically in #42058479Shanitashank
S
8
  1. By default pROC sets asp = 1 to ensure the plot is square and both sensitivity and specificity are on the same scale. You can set it to NA or NULL to free the axis and fill the chart, but your ROC curve will be misshaped.

    plot(g1, asp = NA)
    

    Using par(pty="s") as suggested by Joe is probably a better approach

  2. This is purely a labeling problem: note that the x axis goes decreasing from 1 to 0, which is exactly the same as plotting 1-specificity on an increasing axis. You can set the legacy.axes argument to TRUE to change the behavior if the default one bothers you.

    plot(g1, legacy.axes = TRUE)
    
Shanitashank answered 24/4, 2017 at 12:35 Comment(0)
B
1

A good shortcut to getting a square plot is to run the following before plotting:

par(pty="s")

This forces the shape of the plot region to be square. Set the plotting region back to maximal by simply resetting the graphics device and clearing the plot.

dev.off()

As pointed out by @Calimo, there is the legacy.axes argument to reverse the x-axis and the label is also changed automatically. You can run ?plot.roc to see all the pROC plotting options.

Example

# Get ROC object
data(aSAH)
roc1 <- roc(aSAH$outcome, aSAH$s100b)

# Plot
par(pty="s")
plot(roc1, grid = TRUE, legacy.axes = TRUE)

# Reset graphics device and clear plot
dev.off()
Barracuda answered 9/12, 2016 at 23:4 Comment(8)
Thank you Joe. Let me try thisHumiliating
One additional question. How do I change the actual scale. At the moment it it in descending order from 1 to 0. I want it from 0 to 1.Humiliating
The x axis in the OP's figure really is the specificity. Labeling it 1-Sp would be misleading without also reversing the axis.Shanitashank
Agreed with@Calimo. Just forcing the label to change would be misleading. Never do that. Rather change the scale from 0 to 1 (increasing order) by using legacy. axis argument.Magnuson
legacy. axis takes value TRUE or FALSE(Default) indicating if the specificity axis (x axis) must be plotted as as decreasing “specificity” (FALSE, the default) or increasing “1 - specificity” (TRUE) as in most legacy software. This affects only the axis, not the plot coordinatesMagnuson
@Joe, please also tell how to reset the plot setting after using par(pty="s") for this plot?Magnuson
par(pty="m"). I've added it to the answer above.Barracuda
Actually you can also just reset the graphics device dev.off() as well.Barracuda

© 2022 - 2024 — McMap. All rights reserved.