簡體   English   中英

ggplot2 geom_bar plot其中..count ..大於X.

[英]ggplot2 geom_bar plot where ..count.. greater than X

如果count大於X,我如何告訴ggplot繪制點。 我知道這應該很容易,但我無法弄明白。 就像是

ggplot(items,aes(x=itemname,y=..count..))+geom_bar(y>X)

如果我正確理解您的問題(您沒有提供示例數據),最簡單的方法是生成您想要在ggplot之外繪制的數據框。 所以

##Example data
items = data.frame(itemname = sample(LETTERS[1:5], 30, replace=TRUE))
##Use table to count elements
items_sum = as.data.frame(table(items))

然后情節

X = 4
ggplot(items_sum[items_sum$Freq > X,], aes(x=items,y=Freq)) + 
    geom_bar(stat="identity")

我可能在這里弄錯了,但你不能簡單地通過geom_bar()傳遞子集代碼嗎?

ggplot(items_sum, aes(x=items,y=Freq)) + geom_bar(stat="identity", subset=.(Freq>4))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM