I would like to format the numbers on a continuous axis in a ggplot graph. I would like to have a French formatting for large numbers with a space every three digit (ie "20 000" instead of "20000"). I know it is possible to do it using the format()
function (for instance format(20000, scientific=FALSE, big.mark = " ")
) but I don't know how to combine this function with ggplot. I can imagine that there is an option in the scale_y_continuous()
but I was unable to find the solution by myself.
Here is my gist file.
Use scale_xx() functions It is also possible to use the functions scale_x_continuous() and scale_y_continuous() to change x and y axis limits, respectively.
The scale_x_continuous() and scale_y_continuous() methods can be used to disable scientific notation and convert scientific labels to discrete form.
To add axis breaks in ggplot2 plots in R, we use scale_x_break() and scale_y_break() functions. These functions take a vector as a parameter that has breakpoints. If we need multiple breakpoints we can add those too.
french = function(x) format(x, big.mark = " ")
p + scale_y_continuous(labels=french)
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