Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the thousands separator in a ggplot

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

like image 944
Forzaa Avatar asked Apr 24 '14 08:04

Forzaa


2 Answers

p + scale_y_continuous(labels=function(x) format(x, big.mark = ".", scientific = FALSE)) 
like image 106
lukeA Avatar answered Sep 19 '22 18:09

lukeA


this also works:

p + scale_y_continuous(labels = scales::comma) 
like image 42
Guibor Camargo Salamanca Avatar answered Sep 21 '22 18:09

Guibor Camargo Salamanca