0

how to make a geom_bar() in ggplot2 where the bars start from -0.1? I mean something like this: enter image description here

What I get is this: enter image description here

I want the bar plot to start at the part indicated in red (i.e., from -0.1).

The code:

lasguasimas_stats = data.frame(
          "Muestra" = c('LG1-10','LG1-15', 'LG1-20', 'LG1-25','LG1-30','LG1-35','LG1-40',
                        'LG1-45','LG1-50',  'LG1-55','LG1-60', 'LG1-65','LG1-70',
                        'LG1-75','LG1-80','LG1-85','LG1-90','LG1-95','LG1-100'),
          "Sesgo" = c(-0.004, 0.500,0.639,0.594,0.570, 0.453,0.485,  0.351,0.00045,
                      0.425, 0.383,0.508, 0.196, 0.101, -0.015,0.399,0.323, 0.201,
                      0.390)
        )

ggplot(lasguasimas_stats, aes(x = factor(Muestra, level = unique(Muestra)), 
                                      y = Sesgo))+
  geom_bar(color = NA,
           fill = "#c3c3c3",
           stat = "identity") +

  scale_x_discrete(name = "Muestra") +

  scale_y_continuous(name = "Sesgo",
                     expand = c(0,0),
                     limits = c(-.1,.8),
                     breaks = seq(-.1,.8,.1))+
  
  theme(
    panel.background = element_blank(),
    axis.text = element_text(colour = "black"),
    axis.text.x = element_text(hjust = 1,
                               angle = 45,
                               size = 6,
                               margin = margin(t = 0.1)),
    axis.ticks = element_line(color = "black",
                              size = .2),
    axis.line = element_line(color = "black",
                             size = .3),
    axis.title.x = element_text(margin = margin(t = 8),
                                size = 8),
    axis.title.y = element_text(margin = margin(r = 6),
                                size = 8),
    axis.text.y = element_text(size = 6))+

  geom_hline(yintercept = c(.1, .3),
             size = .2)+

  annotate("text",
           x = 10,
           y = c(.2, .45, .055),
           label = c('bold("Sesgado a fino")',
                     'bold("Sesgado a muy fino")',
                     'bold("Simétrico")'),
           size = 1.5,
           parse = TRUE)

0 Answers0