Trude Slinger
Trude Slinger

Reputation: 33

Horizontally flipping x-axis of ROC-plot without changing data

I'm busy making ROC-plots. In order to get the axis correct, I use scale_x_reverse of ggplot. But when doing so, it seems like the data is changed in such a way that there are sudden drops in sensitivity. Any help to prevent this? See below.

First without flipping the x-axis:

# 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" )

enter image description here

When I activate the #scale_x_reverse( breaks = number_ticks( 8 ) ), I get the following image:

enter image description here

Can anyone help me out? Why is there such a change in the line and how to solve?

Thanks a lot!

I tried several options with changing axes, but nothing helped so far.

Upvotes: 1

Views: 76

Answers (1)

Trude Slinger
Trude Slinger

Reputation: 33

Update: I already found the problem. By adding geom_point I found out that geom_line was connecting the dots in a wrong order. Using geom_path instead of geom_line did the trick.

Upvotes: 1

Related Questions