ggplot2 geom_bar plot其中..count ..大于X [英] ggplot2 geom_bar plot where ..count.. greater than X

查看:342
本文介绍了ggplot2 geom_bar plot其中..count ..大于X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有当count大于 X 时,我该如何告诉ggplot才能绘制点。我知道这应该很容易,但我无法弄清楚。例如

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


解决方案

如果我正确理解你的问题不提供示例数据),最简单的方法是生成您想要在ggplot之外绘制的数据框。因此

  ##示例数据
items = data.frame(itemname = sample(LETTERS [1:5], 30,replace = TRUE))
##使用表来计算元素数量
items_sum = as.data.frame(table(items))
$ b $ p

然后绘图

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


How do i tell ggplot to to plot points only if count is greater than X. I know this should be easy but i couldnt figure it out. something like

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

解决方案

If I understand your question correctly (you haven't provided example data), the easiest way is to generate your the data frame you want to plot outside of ggplot. So

##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))

Then plot

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

这篇关于ggplot2 geom_bar plot其中..count ..大于X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆