Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting numbers on a continuous axis in ggplot

Tags:

r

ggplot2

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.

like image 769
PAC Avatar asked Aug 26 '13 15:08

PAC


People also ask

How do I change axis numbers in ggplot2?

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.

How do I stop Ggplot from scientific notation?

The scale_x_continuous() and scale_y_continuous() methods can be used to disable scientific notation and convert scientific labels to discrete form.

How do I add a break in ggplot2?

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.


1 Answers

french = function(x) format(x, big.mark = " ")

p + scale_y_continuous(labels=french)
like image 84
baptiste Avatar answered Nov 14 '22 23:11

baptiste