ggplot“非有限值”的错误

问题描述:

我具有R数据帧(df),看起来像这样:ggplot“非有限值”的错误

blogger; word; n; total 
joe; dorothy; 17; 718 
paul; sheriff; 10; 354 
joe; gray; 9; 718 
joe; toto; 9; 718 
mick; robin; 9; 607 
paul; robin; 9; 354 
... 

我想使用ggplot2绘制n每个blogger除以total

我有这样的代码:

ggplot(df, aes(n/total, fill = blogger)) + 
    geom_histogram(show.legend = FALSE) + 
    xlim(NA, 0.0004) + 
    facet_wrap(~blogger, ncol = 2, scales = "free_y") 

但它产生这样的警告:

Warning message: 
“Removed 1474 rows containing non-finite values (stat_bin).”Warning message in rep(no, length.out = length(ans)): 
“'x' is NULL so the result will be NULL” 
+1

非有限由零 – Hugh

+3

表明除法这是因为你的范围内,0.0004的上端,是小于的的'N/total'值的许多(或许是全部) –

在,你从工作example plot here,有更高的n/total很长的尾巴,从而使用xlim()。试着让你的情节没有任何改变的x轴的限制;在你的情况下你可能根本不需要调整。

ggplot(df, aes(n/total, fill = blogger)) + 
    geom_histogram(show.legend = FALSE) + 
    facet_wrap(~blogger, ncol = 2, scales = "free_y")