0

I was wondering if there is a way for me to adjust the location where the notches of the axis meet the edge of the bar plot. If you see in the image below all the notches of the x-axis line up in the center of the bar, I would like them to line up with the left edge of the bar! Is this possible?

Edit: Heres what my code looks like

hr6_xy = data.frame(hr6_bins, hr6_Occur)

hr6_plot = ggplot(hr6_xy, aes(hr6_bins, hr6_Occur)) + 
  geom_bar(stat = "identity",
           color = 'black', fill = 'pink', width = 1)
hr6_plot = hr6_plot + theme_bw()
hr6_plot = hr6_plot + ggtitle("hr6 (68 sites)")
hr6_plot = hr6_plot + xlab("Distance to TSS from Motif Center, kb")
hr6_plot = hr6_plot + ylab("Occurances")
hr6_plot

Bar Plot

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Rajiv171
  • 3
  • 2
  • 2
    Does this answer your question? [Force the origin to start at 0](https://stackoverflow.com/questions/13701347/force-the-origin-to-start-at-0) – Rémi Coulaud Jul 09 '20 at 18:12
  • 2
    Please provide code and a data sample to show us how you made the plot. – eipi10 Jul 09 '20 at 18:16

1 Answers1

0

Two ways I can think of:

(a) shift the position of the bars with position_nudge

ggplot(data = iris, aes(y=Sepal.Length, x = Species)) +
  geom_bar(stat = "summary", width = 0.8,
           position = position_nudge(x = 0.4))

(b) shift the position of the ticks on the x-axis with scale_x_continuous

ggplot(data = iris, aes(y=Sepal.Length, x = as.numeric(Species))) +
  geom_bar(stat = "summary", width = 0.8) +
  scale_x_continuous(breaks = c(0.6, 1.6, 2.6), 
                     labels = levels(iris$Species))
AndreasM
  • 902
  • 5
  • 10