0

I have the following figure.

plot

As you can see the breaklines for the x scale (which is scaled discrete in this case) go right through the different bars. I want to these breaklines to form "lanes" in which the bars are nicely fitted. So instead of having my breaks go through the bar, I would like them to lie at the edge of each bar.

I experimented a lot with the scale_x_discrete function but just can't seem to figure out how to achieve this...

Jordo82
  • 796
  • 4
  • 14
WBM
  • 129
  • 4
  • Welcome to SO! Could you make your problem reproducible by sharing a sample of your data and the code you're working on so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Nov 21 '18 at 13:26

1 Answers1

1

You can create some fake gridlines using geom_vline while hiding the true gridlines.

library(tidyverse)

data <- data.frame(x = letters[1:10], y = runif(10), stringsAsFactors = FALSE)

data %>%
  ggplot(aes(x, y)) + 
  geom_bar(stat = "identity") + 
  coord_flip() + 
  geom_vline(xintercept = seq(1.5, 9.5, 1), color = "white") + 
  theme(panel.grid = element_blank())

plot

Jordo82
  • 796
  • 4
  • 14