ggplot2中的数字格式轴标签? [英] Number formatting axis labels in ggplot2?

查看:440
本文介绍了ggplot2中的数字格式轴标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  x < -  rnorm(100,平均值= 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)

哪个方法可行,但ggplot2默认为科学记数法,这对我的观众来说是不合适的。如果我想通过输入来更改x轴标签格式:

  p.new + scale_x_continuous(labels = comma)

我得到:

 结构错误(list(call = match.call(),aesthetics = aesthetics,:
object'comma'not found

我做错了什么?我注意到语言最近从formatter变成了labels。也许我误读了man page?

编辑:我确实误读了手册页

需要加载 library在试图这样做之前。

解决方案

需要加载缩放),然后再尝试。


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.

解决方案

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

这篇关于ggplot2中的数字格式轴标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆