R - Customizing X Axis Values in Histogram

101,893

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))
Share:
101,893
user1094628
Author by

user1094628

Updated on July 09, 2022

Comments

  • user1094628
    user1094628 almost 2 years

    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.

  • christopherlovell
    christopherlovell over 9 years
    Looks like xaxt is now depricated in the call to hist()
  • Josh O'Brien
    Josh O'Brien over 9 years
    @polyphant -- Hmm. That's odd. It still works just fine for me in R version 3.1.2 (though any explicit mention of it seems to have been removed from the documentation).
  • christopherlovell
    christopherlovell over 9 years
    Just tried again to be sure and it now works (sorry..) but it has disappeared from the docs. You can call axes=F but this removes both axes.