dquestions
dquestions

Reputation: 19

How do I change the x axis with ggplot

R noob here, my data set has a numerical variable called agegrp and it ranges from 1-7.

I'm trying to plot a histogram using the following code

ggplot(data, aes(x=agegrp)) + geom_histogram(colour="black", binwidth = 0.5)

But the x-axis only contains 2, 4, 6. What do I add/ change so that it shows 1-7?

Upvotes: 1

Views: 54

Answers (1)

Duck
Duck

Reputation: 39595

Try with this:

#Code
ggplot(data, aes(x=agegrp)) +
  geom_histogram(colour="black", binwidth = 0.5)+
  scale_x_continuous(breaks=seq(1,7,by=1))

Upvotes: 1

Related Questions