调整ggplot坐标轴方向:ROC图X轴1需移至另一侧且图形不动
Great question! I've run into this exact issue before with pROC's ggplot2 integration. The good news is there are two straightforward solutions, and the first one mirrors the legacy.axes = TRUE fix you used in base R:
1. Use the built-in legacy.axes parameter in ggroc
The ggroc() function from the pROC package actually supports the same legacy.axes argument as the base R roc.plot() function. Setting this to TRUE will flip the X-axis so that 1 (representing 1 - Specificity / False Positive Rate) is on the right side, while keeping your ROC curves in their correct position.
Just modify your code like this:
ggroc(list(ROC_base = roc_base, ROC_optimised = roc_optimised), legacy.axes = TRUE)
This will align your plot with the standard ROC axis convention you're used to from base R.
2. Manually reverse the X-axis (if you need more control)
If for some reason you can't use the legacy.axes parameter, you can manually reverse the X-axis using ggplot2's scale_x_reverse() function, and adjust the axis label to match the 1 - Specificity interpretation:
ggroc(list(ROC_base = roc_base, ROC_optimised = roc_optimised)) + scale_x_reverse(name = "1 - Specificity (False Positive Rate)") + labs(y = "Sensitivity (True Positive Rate)")
This achieves the same axis flip without altering the curve positions.
Either method will fix your X-axis direction issue while keeping your ROC curves in place.
内容的提问来源于stack exchange,提问作者user113156

