Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number formatting axis labels in ggplot2?

Tags:

r

ggplot2

I'm plotting a fairly simple chart using ggplot2 0.9.1.

x <- rnorm(100, mean=100, sd = 1) * 1000000 y <- rnorm(100, mean=100, sd = 1) * 1000000 df <- data.frame(x,y)  p.new <- ggplot(df,aes(x,y)) +   geom_point() print(p.new) 

Which works, but ggplot2 defaults to scientific notation that is inappropriate for my audience. If I want to change the x-axis label format by entering:

p.new + scale_x_continuous(labels = comma) 

I get:

Error in structure(list(call = match.call(), aesthetics = aesthetics, : object 'comma' not found

What am I doing wrong? I note that the language changed recently from "formatter" to "labels". Perhaps I'm misreading the man page?

Edit: I was indeed misreading the man page

Need to load library(scales) before attempting this.

like image 628
mediaczar Avatar asked Aug 16 '12 12:08

mediaczar


1 Answers

One needs to load library(scales) before attempting this.

like image 191
mediaczar Avatar answered Sep 19 '22 04:09

mediaczar