Change the thousands separator in a ggplot

Forzaa picture Forzaa · Apr 24, 2014 · Viewed 14.7k times · Source

While making a bar plot with ggplot I run into troubles getting the preferred thousands separator. I would like thousands to be separated by a dot instead of a comma. Like this it gives no separator:

require(ggplot2)
require(scales) 
options(scipen=10)
D = data.frame(x=c(1,2),y=c(1000001,500000))
p = ggplot(D,aes(x,y)) + geom_bar(stat="identity") 
p

and like this it gives a comma:

p + scale_y_continuous(labels=comma)

How do you get a dot as thousands separator? I can't find documentation on which types of other labels exist besides some examples on http://docs.ggplot2.org/0.9.3.1/scale_continuous.html.

Thanks in advance,

Forza

Answer

lukeA picture lukeA · Apr 24, 2014
p + scale_y_continuous(labels=function(x) format(x, big.mark = ".", scientific = FALSE))