[R] Thousand separator on axis
Duncan Murdoch
murdoch at stats.uwo.ca
Sat Mar 7 01:38:30 CET 2009
Waldir Leôncio wrote:
> Is there an easy way to add a thousand separator mark on the axis of a
> plot? The best solution I've found so far is the following:
>
> y <- seq(0, 100000, 10000)
> plot(y, yaxt = "n", ylab = "")
> axis(2, at = y, labels = formatC(y, big.mark = " ", format = "d"), las=2)
>
> But that seems like quite a hassle to do every time around. Is there a way
> to get the same output using less parameteres?
Sure: just write a function to do it. Assuming y is the only thing
that varies,
myplot <- function(y) {
plot(y, yaxt = "n", ylab = "")
axis(2, at = y, labels = formatC(y, big.mark = " ", format = "d"), las=2)
}
then myplot(y) is all you need to type. (If you want to be able to
specify titles, etc., just include a ... arg to myplot.)
Duncan Murdoch
More information about the R-help
mailing list