2017-04-18 149 views
1

我具有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'值的許多(或許是全部) –

回答

3

在,你從工作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")