[R] Thousand separator in format of axis

Marc Schwartz MSchwartz at mn.rr.com
Mon Sep 18 00:24:33 CEST 2006


On Sun, 2006-09-17 at 17:47 -0400, Ruben Roa Ureta wrote:
> Hi:
> How can i make that the numbers in the tick annotations of an axis be
> written as, say 20 000 and not 20000 (i.e. with the little gap seprating
> thousands)?
> Thanks
> Ruben


There are several ways to format numbers:
  ?format
  ?sprintf  
  ?formatC

A quick example:

 y <- seq(0, 100000, 10000)
 
 # Set the y axis so that it does not get drawn
 # See ?par
 plot(1:11, y, yaxt = "n", ylab = "")

 # Use formatC() and set 'big.mark' to " "
 # See ?axis also
 axis(2, at = y, labels = formatC(y, big.mark = " ", format = "d"), 
      las = 2)

 
HTH,

Marc Schwartz



More information about the R-help mailing list