问题描述
我使用 cut 和 classIntervals 对 R 中的数据进行分组,然后我用 ggplot2 绘制这些数据.因此,按 n=3 的分位数进行切割的基本操作如下所示:
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)
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]
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]
我该如何实现?如果您有其他方法而不是 cut 和 classInt 来实现相同的结果,我们将不胜感激.
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.
推荐答案
在cut
函数中使用参数dig.lab
:
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]
这篇关于在 ggplot2 中使用没有科学记数法的 R 标签中的 cut 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!