Home > OS >  The error bars appear vertically using geom_errorbarh
The error bars appear vertically using geom_errorbarh

Time:09-15

Using the below code and dataset, I have created the plot below. My expectation from the code was horizontal error bars instead of vertical bars. I wonder to know how can I visualize the bars horizontally.

Thanks,

NM

#My data

discrimination <- structure(list(Mean = c(0.617364075449035, 0.57284608439026, 
                        0.496959052786028, 0.460522529509851, -0.0824568013522042, -0.509293992266701),
               variable = c("A", "B", "C", "D", "E", "F"),  
cilow = c(0.615581317704699, 0.571019568616708, 0.495348349475911, 0.458631736688209, -0.0842685444311714, -0.511175368198272), 
cihigh = c(0.619146833193371, 0.574672600163811, 0.498569756096144, 0.462413322331492, -0.080645058273237, -0.5074126163351),rank = 1:6),
row.names = c("A", "B", 
              "C", "D", "E", 
              "F"), class = "data.frame")

#my plot codes start here

    discrimination_plot <- ggplot(discrimination, aes(y = rank, x = Mean))  
  geom_point(shape = 18, size = 1)    
  geom_errorbarh(aes(xmin = cilow, xmax = cihigh), height = 0.25)  
  geom_vline(xintercept = 0, color = "red", linetype = "dashed", cex = 1, alpha = 0.5)  
  scale_y_continuous(name = "", breaks=1:6, labels = discrimination$variable, trans = "reverse")  
  xlab("Parameter")   
  ylab(" ")   
  theme_classic()  
  theme(panel.border = element_blank(),
        panel.background = element_blank(),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), 
        axis.line = element_line(colour = "black"),
        axis.text.y = element_text(size = 12, colour = "black"),
        axis.text.x.bottom = element_text(size = 12, colour = "black"),
        axis.title.x = element_text(size = 12, colour = "black")) ggtitle("XXX")

discrimination_plot

enter image description here

CodePudding user response:

They are horizontal, but very small.

Let´s add a value in xmax, just for fun, xmax = cihigh 1

discrimination_plot <- ggplot(discrimination, aes(y = rank, x = Mean))  
  geom_point(shape = 18, size = 1)    
  geom_errorbarh(aes(xmin = cilow, xmax = cihigh   1), height = 0.25)  
  geom_vline(xintercept = 0, color = "red", linetype = "dashed", cex = 1, alpha = 0.5)  
  scale_y_continuous(name = "", breaks=1:6, labels = discrimination$variable, trans = "reverse")  
  xlab("Parameter")   
  ylab(" ")   
  theme_classic()  
  theme(panel.border = element_blank(),
        panel.background = element_blank(),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), 
        axis.line = element_line(colour = "black"),
        axis.text.y = element_text(size = 12, colour = "black"),
        axis.text.x.bottom = element_text(size = 12, colour = "black"),
        axis.title.x = element_text(size = 12, colour = "black")) ggtitle("XXX")

discrimination_plot

enter image description here

  • Related