水平翻转 ROC 图的 x 轴而不更改数据

问题描述 投票:0回答:1

我正忙着制作 ROC 图。为了使轴正确,我使用ggplot的scale_x_reverse。但这样做时,数据似乎发生了变化,敏感度突然下降。有什么帮助可以防止这种情况发生吗?见下文。

首先不翻转x轴:

# ROC-curve with inverted specificity axis
roc_plot <- ggplot( data = data_plot, aes( x = spec, y = sens ) ) +
  geom_area( fill = "#02a2ad", alpha = 0.06 ) +
  geom_line( linewidth = 0.8, colour = "#02a2ad" ) +
  geom_segment( aes( x = 100, xend = 0, y = 0, yend = 100 ), linewidth = 1, linetype = 3, colour = "#939899" ) +
  xlab( "Specificity (%)" ) +               
  ylab( "Sensitivity (%)" ) +
  scale_y_continuous( breaks = number_ticks( 8 ) ) +
  #scale_x_reverse( breaks = number_ticks( 8 ) ) +
  coord_flip()+
  theme_classic() +
  annotate( "text", label = paste0( "AUC = ", round( roc$auc[ 1 ], 3 ) ),
            x = 20, y = 11, size = 4, fontface = "bold", colour = "#02a2ad" )

当我激活#scale_x_reverse(breaks = number_ticks(8))时,我得到以下图像:

有人可以帮我吗?为什么线路会有这样的变化,如何解决?

非常感谢!

我尝试了几种改变轴的选项,但到目前为止没有任何帮助。

ggplot2 roc
1个回答
1
投票

更新:我已经发现问题了。通过添加 geom_point 我发现 geom_line 以错误的顺序连接点。使用 geom_path 而不是 geom_line 就达到了目的。

© www.soinside.com 2019 - 2024. All rights reserved.