2013-02-12 82 views
1

我得到一吨的小数位数为我在y轴值当我使用这样的命令ggplot东西:我似乎无法圆值与ggplot

x <- c(39.029998779296875000, 39.080001831054687500, 38.990001678466796875, 39.000000000000000000, 38.990001678466796875) 
example <- data.frame(i=1:5, X=x) 
ggplot(example, aes(i, y=foo, color=variable)) + geom_line(aes(y=X, color='X')) 

什么是此时,相应的告诉ggplot将值调整为没有那么多小数位的方法?

下面是这个命令我的输出:

This image is the output!

这里是sessionInfo()输出 - 这里没有什么看起来可疑对我说:

> sessionInfo() 
R version 2.15.0 (2012-03-30) 
Platform: x86_64-unknown-linux-gnu (64-bit) 

locale: 
[1] C 

attached base packages: 
[1] grid  grDevices graphics stats  datasets utils  methods base 

other attached packages: 
[1] ggplot2_0.9.0 

loaded via a namespace (and not attached): 
[1] MASS_7.3-17  RColorBrewer_1.0-5 colorspace_1.1-1 dichromat_1.2-4 digest_0.5.2  memoise_0.1  munsell_0.3  plyr_1.7.1  \ 

[9] proto_0.3-9.2  reshape2_1.2.1  scales_0.2.0  stringr_0.6  tools_2.15.0 
+3

码。不。重复的。 – joran 2013-02-12 23:24:14

+0

不是第一次(甚至第二次)这个提问者被建议提出可重复问题。 – 2013-02-12 23:26:10

+0

编辑为只有可重现的代码 – 2013-02-12 23:30:03

回答

3

我觉得这是一个问题,您的digits选项。我可以重现如果我设置options(digits=22),而不是使用7出厂默认值,这与该数据小数点后只给出2位:

print(x,digits=7) 
[1] 39.03 39.08 38.99 39.00 38.99 

所以,尽量用还原它:

options(digits=7) 
+0

不错的猜测。允许我重现问题。 – 2013-02-13 02:04:30

+1

在之前对@PalaceChen的编辑声称设置'options(digits = 3)'没有解决问题,但我强烈怀疑他们可能只是被混淆了,并认为他们重置它时,实际上他们没有'吨。 – joran 2013-02-13 03:04:34

+0

这是正确的!我很惊讶。我的.Rprofile有选项(数字= 19),即使在R会话中我称为选项(数字= 3)或选项(数字= 5),它似乎没有改变它。我很好奇为什么这个覆盖不会发生,一旦我打开R会议?我必须在.Rprofile中才能使用它 – 2013-02-13 06:22:32