Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
642 views
in Technique[技术] by (71.8m points)

cut function in R- labeling without scientific notations for use in ggplot2

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...