Error bars - geom_errorbar the vertical dash is way too long, how to adjust the size of the vertical and horizontal error bars

Hello everyone,

I have a problem with vertical error bars they - are way too long and seems to be double error bars

This is the following code I used:

ggplot(XTTCombined, aes( x = Drug, y = Absorbance))+
  labs(title = "Comparison of the effect of Vehicle and Nicotinic Acid on microglia",
       caption = "XTT Assay") +
  labs(x = expression(paste("Treatment")))+
       ylab(expression(paste("Absrobance % Change" ~ "(",   A[540], " - ", A[650] ~ nm, ")"))) +
   geom_point(aes(colour = "tomato"))+
   scale_color_manual(name = "Final concentrations and volumes",
                     labels = c( 
                                bquote("Vehicle  (10µL of"~dH[2]*"O)"), 
                                bquote("Nicotinic Acid(10µL of 1mM)")),
                     values = c(
                                "Vehicle(10µL of dH20)" = "#2171B5", 
                                "Nicotinic Acid (10µL of 1mM)"= "#D1E5F0"))+
               fill=c("#2171B5", "#DEEBF7"),
               notch = FALSE)+
  stat_summary(fun = mean, 
               size=0.2) + 
  stat_boxplot(aes(Drug, Absorbance),
               geom = "errorbar", 
               width = 0.2)+
                stat_summary( = mean_se, geom = "errorbar")+

  scale_x_discrete(labels = c("Vehicle (Control)", "Nicotinic Acid  (1 mM)"))+
  stat_compare_means(label.y = 280,
                     label.x = 1.41)+
  scale_y_continuous(breaks = c(0,25, 50,75,100,125,150,175,200,225,250,275))+
 geom_signif(comparisons = list(c("Vehicle", "NicAcid")), map_signif_level = TRUE, y_position = c(285), colour = "#cf1b1b")+
                  theme_bw() +
        theme(panel.grid.major = element_line(colour = "#d3d3d3"),
              panel.grid.minor = element_blank(),
              panel.border = element_blank(), panel.background = element_blank(),
              plot.title = element_text(size = 14, face = "bold"))+
                   theme(axis.text.x = element_text(face="bold", color="#3142b0", 
                           size=8.9, angle=0),
                         axis.text.y = element_text(face="bold", color="#3142b0", 
                           size=8.9, angle=0))+
  scale_shape_manual('',values = 18)+
  theme(legend.spacing.y = unit(0.01, "cm"))+
  theme(legend.position = c(0.79, .93),
        legend.justification = c("left", "top"),
        legend.key = element_rect(colour = NA, fill = NA),
        legend.background = element_rect(colour = NA, fill = NA))

And this is DataUsed

Thank you so much for any help or tips.

1 Like

Hi remi133, check this example and try to make. Maybe this could help you.

1 Like

Thank you so much for your reply, however, it does not solve the problem of the second error bars that appear there. While I can change the width of the main error bars somehow I cannot do anything with the second error bars which I do not really need

Ok, I found a solution to my own issue. So in the code

stat_boxplot(aes(Drug, Absorbance),
               geom = "errorbar",  #1st geom="errorbar"
               width = 0.2)+
                stat_summary( = mean_se, geom = "errorbar") #2nd geom = "errorbar"

Hence, I had double error bars.

Thank you

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.