0

I am trying to change the widht of the geom_errorbar() 'whiskers' of the following ggplot. In my eyes it seems like a bug. The usual width = x specification for the errorbars does not work here. it interferes with the width = x specification of the position = "dodge argument. Is there any way i can specify that width = x is only for geom_errorbars?

 library(tidyverse)
    
    
    
    data <- as_tibble(rbind(c("out", 14, 2.3,T),
                            c("in", 15, 2.7,T),
                            c("far", 18, 4,T),
                            c("out", 14, 2.3, F),
                            c("in", 17, 2.3, F),
                            c("far", 13, 2.3, F)
                            )
                      )
    colnames(data) <- c("position", "mean", "se", "dead")
    data$mean <- as.numeric(as.character(data$mean))
    data$se <- as.numeric(as.character(data$se))
    
    data
    
    ggplot(data = data, aes(x = position, y = mean, fill = dead)) +
      geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                    stat = "identity",
                    position = "dodge", 
                    width = 3)+                              # its about this line !
      geom_bar(stat = "identity",
               position = "dodge")

This is the plot given out by the code above:

Image

the errorbars are all over the place. without the width = x specification they are where they should be, but i would like them to be smaller !

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • Please read the help text. From the examples: "Because the bars and errorbars have different widths we need to specify how wide the objects we are dodging are `dodge <- position_dodge(width=0.9)`. – Henrik Jul 01 '20 at 13:58
  • 1
    OP : think of is this way. The width of the geom is the distance across for one geom (bar or whisker here). The *width of the dodge* can be set independent of that by using `position=position_dodge(width=...)`. Using `position="dodge"` sets the width of the dodge to be equal to the width of the geom. So this means when you change the width of the error bar, the dodge width also changes. Your solution is to specify the same width *of the dodge* via `position=position_dodge()` for both geoms to be the same, then you can specify different widths for each geom. – chemdork123 Jul 01 '20 at 14:05

0 Answers0