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.
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.
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.
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.
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.
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)
I'm just taking a stab in the dark, but scale_y_continuous(labels = space)
might do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With