'geom_pointrange y-axis negative value ordering

I am attempting to create a dot and CI plot using results from different regression results. I created a dataframe that contains the betas, lower limit, upper limit, and some grouping variable.

some sample data:

count <- 1:8

race  <- c(rep(c("Black","Non-Black"),4))

betas <- c(0.97,-0.63,
           0.77,-0.07,
           0.07,-0.07,
           0.16,-0.46)

lower <- c(-0.41,-2.16,
            0.29,-0.58,
           -0.44,-0.64,
           -0.45,-1.22)
           
upper <- c(2.36,0.89,
           1.25, 0.45,
           0.59,0.49,
           0.78,0.3)

plot4 <- as.data.frame(cbind(count,race,outcome,betas,lower,upper))

Using the following code

ggplot(plot4, aes(x=reorder(count, sort(as.numeric(count))), 
                  y=betas, 
                  group=outcome,
                  color=race))+
  geom_pointrange(aes(ymin=lower,ymax=upper))+
  theme_classic()

results in a Y-axis that is "out of order": plot_example

Negative fractions are plotted as "smaller" (further from zero) than negative integers and the intervals do not contain the value they were created from.

I would like to fix the issue so that the y-axis goes from the most negative (e.g.-2.16) to the most positive (e.g. 2.36)

I tried re-ordering the y-axis as I did with the x-axis but that didn't help.

I'm also not convinced that this is the best way to present the data so really any advice or fixes would be greatly appreciated.

Thank you in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source