R - Customizing X Axis Values in Histogram

user1094628 picture user1094628 · Dec 12, 2011 · Viewed 87k times · Source

I want to change the values on the x axis in my histogram in R.

The computer currently has it set as

0, 20, 40, 60, 80, 100.

I want the x axis to go by 10 as in:

0,10,20,30,40,50,60,70,80,90,100.

I know to get rid of the current axis I have to do this

(hist(x), .... xaxt = 'n')

and then

axis(side = 1) .....

But how do I get it to show the numbers that I need it to show?

Thanks.

Answer

Josh O'Brien picture Josh O'Brien · Dec 12, 2011

The answer is right there in ?axis...

dat <- sample(100, 1000, replace=TRUE)
hist(dat, xaxt='n')
axis(side=1, at=seq(0,100, 10), labels=seq(0,1000,100))