給定一個數據幀如下:繪圖條以降序顯示特定列的值的計數?
V1 V2
a 089
a 065
a 012
b 101
b 110
現在,我想繪製,酒吧,有在作爲y軸的第一列V1
的值的計數,它應該是降序排列。
我曾嘗試:
library(ggplot2)
ggplot(data = df, aes(reorder(V1,..count..), y = ..count..)) +geom_bar(stat = "count")
但失敗並生成一個警告:
Warning messages:
1: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
2: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf
3: In min(diff(sort(x))) : no non-missing arguments to min; returning Inf
4: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
5: Computation failed in `stat_count()`:
arguments imply differing number of rows: 0, 1
我也試圖改變stat = "bin"
,但它沒有工作也沒有。 你有什麼想法嗎?
在此先感謝!
僅供參考,這是不是你想要繪製的直方圖,這是一個柱狀圖。 – MLavoie
@MLavoie謝謝你的提醒。我改變了標題。 – user5779223
@MLavoie它是一個直方圖 – mtoto