Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

European/french thousand separator in ggplot

Tags:

r

ggplot2

I'm trying to format the y axis in a ggplot graph with a space (and not a comma) as thousand separator ; something like 10 000 and not 10,000. I can't found it in the scale_y_continuous help.

Thanks for any hint.

like image 601
user2035816 Avatar asked Feb 02 '13 19:02

user2035816


People also ask

How do you separate thousands into groups of thousands?

Likewise, while the U.K. and U.S. use a comma to separate groups of thousands, many other countries use a period instead, and some countries separate thousands groups with a thin space. Table 1-3 shows some commonly used numeric formats.

What is the example data in ggplot2?

Both of these examples will be based on the following example data: Our example data is a data.frame consisting of 1000 rows and two columns x and y. Both variables contain random numeric values. For this tutorial, we’ll also have to install and load the ggplot2 and scales packages.

How do I use labelling in ggplot2?

Labelling functions are designed to be used with the labels argument of ggplot2 scales. In this example, we show the number as millions ‘M’, by providing the suffix and the scale of 1 (-6). In the comments I’ve also entered the code to display the values as thousands on the Y-axis.

What countries use a period for decimal separator?

Great Britain and the United States are two of the few places in the world that use a period to indicate the decimal place. Many other countries use a comma instead. The decimal separator is also called the radix character.


Video Answer


2 Answers

As @David and @joran just said.

First, define the label formatter:

space <- function(x, ...) { 
  format(x, ..., big.mark = " ", scientific = FALSE, trim = TRUE)
}

and then use it with scale_y_continous:

plot + scale_y_continuous(labels = space)
like image 197
reinholdsson Avatar answered Nov 14 '22 13:11

reinholdsson


I'm just taking a stab in the dark, but scale_y_continuous(labels = space) might do the trick.

like image 20
David Avatar answered Nov 14 '22 11:11

David