在没有科学记号的R-标签中用于ggplot2的剪切功能 [英] cut function in R- labeling without scientific notations for use in ggplot2

查看:139
本文介绍了在没有科学记号的R-标签中用于ggplot2的剪切功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cut和classIntervals将R中的数据分组,然后我使用ggplot2进行绘图。因此,一个n = 3分位数的基本操作应该如下所示:

  library(classInt)

a< -c(1,10,100,1000,100000,1000000)
b< -cut(a,
breaks = data.frame(
classIntervals(
a,n = 3,method =quantile)[2])[,1],
include.lowest = T)

其中 b 应该是:

  [ 1] [1,70] [1,70](70,3.4e + 04](70,3.4e + 04)(3.4e + 04,1e + 06)(3.4e + 04,1e + 06)
级别:[1,70](70,3.4e + 04)(3.4e + 04,1e + 06)

所以这个输出的第一行是一个带有我可以在ggplot2中使用的分组数据的向量,但是不要让这个向量用科学记数法表示,我希望标签是 [ 1,70](70,34000)(3400,1000000)



我该如何存档?如果有任何帮助,你有其他的方法,而不是削减和classInt达到相同的结果。

解决方 cut 函数中使用参数 dig.lab

  a< -c(1,10,100,1000,100000,1000000)
b <-cut(a,
breaks = data。 (
classIntervals(
a,n = 3,method =quantile)[2])[,1],
include.lowest = T,dig.lab = 10)##使用的位数
b
[1] [1,70] [1,70](70,34000](70,34000)
[5](34000,1000000](34000, 1000000]
级别:[1,70](70,34000)(34000,1000000]


I use cut and classIntervals to group data in R which I later plot with ggplot2. So a basic operation cutting by quantiles with n=3 would look like this:

library(classInt)

a<-c(1,10,100,1000,100000,1000000)
b<-cut(a, 
breaks=data.frame(
  classIntervals(
    a,n=3,method="quantile")[2])[,1],
include.lowest=T)

where b would be:

[1] [1,70]          [1,70]          (70,3.4e+04]    (70,3.4e+04]    (3.4e+04,1e+06] (3.4e+04,1e+06]
Levels: [1,70] (70,3.4e+04] (3.4e+04,1e+06]

so the first line of this output is a vector with my grouped data which I can use in ggplot2. But rather than having this vector in scientific notation I would like the labels to be [1,70] (70,34000] (3400,1000000]

How can I achive that?Any help would be appreciated, also if you have other methods rather than cut and classInt to achive the same result.

解决方案

Use argument dig.lab in cut function:

a<-c(1,10,100,1000,100000,1000000)
b<-cut(a, 
breaks=data.frame(
  classIntervals(
    a,n=3,method="quantile")[2])[,1],
include.lowest=T,dig.lab=10) ##Number of digits used
b
[1] [1,70]          [1,70]          (70,34000]      (70,34000]     
[5] (34000,1000000] (34000,1000000]
Levels: [1,70] (70,34000] (34000,1000000]

这篇关于在没有科学记号的R-标签中用于ggplot2的剪切功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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