1

I have a variable, Avg_Salary, where the min is $16,970 and the max is $5,991,000. However, when I go to plot a histogram in R, it shows the values on the x and y axis in scientific notation it looks like. 0e+00, 1e+06, 2e+06, etc. How do I get it to show the numbers in the thousands and millions. Is it because they are too big to be displayed on the graph? Can I edit this to change my axis?

hist(rs$Avg_Salary, freq=F, xlab = "Avg_Salary", main = "Histogram of Avg_Salary")

![histogram][1]

Pat
  • 11
  • 4

1 Answers1

1

You can pass the argument axes=F, and then make your own axis.

# plot your histogram without axes
hist(blah blah blah ,
    axes=F)

# plot the usual y-axis
axis(2)

# get the values where the ticks on the x-axis would normally be
ticks <- axTicks(1)

# format the tick labels (you could get fancy here)
lables_in_millions <- paste0(round(x / 1e6, 1), "M")

# add the x axis
axis(1,at=ticks,lables=lables_in_millions)

The only thing you need to change to use this method on an ordinary plot is to call box(), b/c axes=F will remove the box as well as the axis ticks and labels.

Jthorpe
  • 9,756
  • 2
  • 49
  • 64