2013-03-19 57 views
21

我使用剪切和classIntervals到R基團的數據,我後面GGPLOT2繪製。因此,通過具有n = 3位數的基本操作切削看起來像這樣:切斷功能在GGPLOT2

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] 
Levels: [1,70] (70,3.4e+04] (3.4e+04,1e+06] 

所以該輸出的第一行是與我的分組數據的載體,其我可以在ggplot2中使用。但我不希望這種載體以科學計數法表示,我希望這些標籤是[1,70] (70,34000] (3400,1000000]

我該如何實現這一目標?

+1

如果有人使用了類似的功能,對數據進行分組,隨意從'Hmisc'包,它實際上做切割bether比我的功能檢查'cut2'如上所述。另請參閱:https://stat.ethz.ch/pipermail/r-help/2007-December/148468.html。在這種情況下,使用'digits = 10'來避免科學記號。 – Joschi 2013-03-19 11:58:28

回答

31

使用參數dig.labcut功能:

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] 
+0

@Jouni Helske - 你會提出,如果數量是一樣的東西10^-17? – novice 2016-07-19 18:53:21