0

I have the following code to plot a histogram using ggplot2.

ggplot(data = plot, aes(x = total_Amg))+
  geom_histogram(binwidth = 1, colour = "black", fill = "white") +
  facet_wrap(~ gentamicin) 

How can I specify what numbers are shown on the x axis of the resulting graph, i.e. show 0 to 8, rather than showing those that was automatically generated (see below)?

enter image description here

Maho
  • 59
  • 1
  • 7
  • 1
    Does this answer your question? [Change x-axis breaks ggplot2](https://stackoverflow.com/questions/33191998/change-x-axis-breaks-ggplot2) – camille Dec 17 '21 at 17:06
  • Also see https://stackoverflow.com/q/22818899/5325862 – camille Dec 17 '21 at 17:10

2 Answers2

1

+scale_x_continuous(breaks=0:8) should do the trick

Quixotic22
  • 2,894
  • 1
  • 6
  • 14
  • thank-you. I've tried this, and for one data set this works but for another it only shows 0 to 5? I want to show 0 to 8 for both graphs. – Maho Dec 19 '21 at 17:20
0

Try adding:

+ scale_x_continuous(breaks = 0:8, labels = 0:8)
Tur
  • 604
  • 4
  • 9