You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调整ggplot坐标轴方向:ROC图X轴1需移至另一侧且图形不动

Fix ROC Plot X-Axis Direction in ggroc

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:56:41