在ggplot Histrogram中应用坐标转换时出错?

时间:2015-10-28 00:39:36

标签: r ggplot2

我有一个数据框,我可以成功生成直方图,如下所示:

x <- c(1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
           1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1082.227051, 1061.021973, 72.625076, 
           893.228271, 605.197388, 15.236160, 1311.000977, 2161.091064, 1.000000, 335.215393, 523.336670, 41.877338,
           467.459686, 1.000000, 1.000000, 751.669617, 20.263149, 2612.868896, 2837.354004, 2214.660889, 31.043751,  
           836.496216, 1419.154053, 84.640457, 2261.688965, 1.000000, 1.533333, 1.000000, 1.155556, 1.000000, 
           1.000000, 1.000000, 1.000000, 1.000000, 1.000000)
df <- as.data.frame(x)
names(df)[1] <- 'values'
df$type <- 'test'

ggplot(df, aes(x=values, fill = type)) + 
  geom_histogram(alpha = 0.7, 
                 aes(y = ..count..),
                 position = 'identity')  

这给了我这张图:

请注意,这些值均不为负数。当我将对数刻度应用于x轴时,

ggplot(df, aes(x=values, fill = type)) + 
  geom_histogram(alpha = 0.7, binwidth=500,
                 aes(y = ..count..),
                 position = 'identity') +
  coord_trans(x="log10")

我收到此错误:

Error in if (zero_range(range)) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In trans$transform(out$range) : NaNs produced

尽管当日志分别应用于数据时,没有x值产生NaN。

> log10(df$values)
 [1] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
[13] 0.00000000 0.00000000 0.00000000 0.00000000 3.03431839 3.02572438 1.86108660 2.95096246 2.78189704 1.18287553 3.11760302 3.33467307
[25] 0.00000000 2.52532395 2.71878117 1.62197907 2.66974416 0.00000000 0.00000000 2.87602700 1.30670694 3.41711762 3.45291352 3.34530724
[37] 1.49197419 2.92246398 3.15202954 1.92757800 3.35443288 0.00000000 0.18563647 0.00000000 0.06279098 0.00000000 0.00000000 0.00000000
[49] 0.00000000 0.00000000 0.00000000

谁能告诉我发生了什么?

0 个答案:

没有答案