如何调整R语言ROC图中AUC值的显示位置?
Hey there! I get it—tweaking the AUC label position on your ROC plot can be tricky even when you’ve set print.auc=TRUE and location. Let’s fix this with a few targeted adjustments using the pROC package’s built-in parameters.
Key Context: pROC’s Coordinate System
First, remember that the location parameter uses relative coordinates (0 to 1):
(0, 0)= Bottom-left corner of the plot(1, 1)= Top-right corner
Your original location=c(0.2,1) places the AUC label near the top-left edge, which might overlap with grid lines or threshold text (from print.thres=TRUE). Let’s adjust this.
Solution 1: Fine-Tune the location Parameter
Simply adjust the x/y values to move the label to a less crowded spot. For example, to place it in the bottom-right corner:
plot(modelroc, print.auc=TRUE, location=c(0.8, 0.2), # Bottom-right area auc.polygon=TRUE, grid=c(0.1, 0.2), grid.col=c("green", "red"), max.auc.polygon=TRUE, auc.polygon.col="skyblue", print.thres=TRUE)
Or if you want it top-right instead:
location=c(0.8, 0.9)
Solution 2: Use print.auc.x and print.auc.y for Precise Control
For even more granularity, replace location with separate x/y parameters for the AUC label:
plot(modelroc, print.auc=TRUE, print.auc.x=0.7, # Exact horizontal position print.auc.y=0.3, # Exact vertical position print.auc.cex=0.8, # Shrink font size if needed auc.polygon=TRUE, grid=c(0.1, 0.2), grid.col=c("green", "red"), max.auc.polygon=TRUE, auc.polygon.col="skyblue", print.thres=TRUE)
The print.auc.cex parameter helps if the label is too large and overlapping other elements.
Solution 3: Avoid Conflicts with Threshold Text
If your AUC label is clashing with the threshold values (from print.thres=TRUE), you can adjust the threshold text position too:
plot(modelroc, print.auc=TRUE, location=c(0.2, 0.8), # Move AUC down from top print.thres.x=0.5, # Adjust threshold text x-position print.thres.y=0.5, # Adjust threshold text y-position auc.polygon=TRUE, grid=c(0.1, 0.2), grid.col=c("green", "red"), max.auc.polygon=TRUE, auc.polygon.col="skyblue", print.thres=TRUE)
Alternatively, temporarily set print.thres=FALSE to test the AUC position without distractions, then re-enable it once you’re happy with the AUC placement.
内容的提问来源于stack exchange,提问作者Kyan

