【问题标题】:Returning categories where the count of an attribute is greater than 0 in RStudio - Barplot返回RStudio中属性计数大于0的类别-Barplot
【发布时间】:2020-03-19 16:23:22
【问题描述】:

我是 R 新手,很抱歉这个基本问题。

我想根据值的出现次数对分类数据进行条形图。 它基于谷歌应用商店数据,我想在条形图中查看“游戏”、“艺术与设计”等下出现的次数。 我的问题是有 20 个奇怪的类别(其中许多有 0 次出现,因为我采用了表现最佳的应用程序的子集 [“topPerforming”])所以当我绘制 barplot 时,它很难阅读,因为它显示了所有类别,包括出现次数为 0 的所有类别。

我想根据表现最好的 5 个类别绘制条形图,但这样做时遇到问题。 当我尝试执行 topPerforming$category > 5 时,我收到一条错误消息:“In Ops.factor(topPerforming$Category, 0) : ‘>’ 对于因子没有意义”

table(topPerforming$Category)
table <- table(topPerforming$Category) # viewing the number of occurences in each category
barplot(prop.table(table(topPerforming$Category)))

任何帮助将不胜感激

【问题讨论】:

    标签: r null bar-chart


    【解决方案1】:

    好吧,如果没有样本数据集,您可以使用dplyr 链来添加出现次数,然后过滤数据集,也许:

    new_data = topPerforming %>% group_by(Category) %>% add_count %>% filter(.,N>5)
    

    如果你有一个 dput sn-p 或示例数据,它应该很容易检查

    【讨论】:

      猜你喜欢
      • 2018-06-17
      • 2011-10-27
      • 2022-10-21
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 1970-01-01
      相关资源
      最近更新 更多