I would like to see the x-axis numbers in my histogram in thousand separated format. So for example,
y <- seq(10000, 100000, 10000)
hist(y)
in this plot, I want to see 10,000 20,000, etc. on the x-axis. Any simple way to get it?
Draw the histogram without an x-axis, then add it manually with axis
:
y <- seq(10000, 100000, 10000)
hist(y, xaxt="n")
axis(side=1, at=axTicks(1),
labels=formatC(axTicks(1), format="d", big.mark=','))
axTicks
calculates the tickmark locations, and formatC
formats the numbers. Here is the result:
The scales
library has a function called comma
which formats the numbers how you want:
library(scales)
Not quite what you wanted, but a start:
q<-quantile(y,prob=seq(0,1,.1));hist(y,breaks=q,labels=comma(q))
Better version, using lattice
:
q<-quantile(y,prob=seq(0,1,.1));histogram(~y,breaks=q,scales=list(at=q,labels=comma(q)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With