【问题标题】:Error- State_count() must not be used ,. How to solve this?错误 - 不得使用 State_count()。如何解决这个问题?
【发布时间】:2018-10-27 13:07:46
【问题描述】:

她想查明美国各个州的犯罪情况。因此,她绘制了数据集“USarrests”,以构建不同州谋杀案数量的条形图。

以下命令给出错误: ggplot(USarrests, aes(x = row.names(USarrests), y = USArrests$Murder, lab)) + geom_bar() + theme(axis.text.x=element_text(angle=90, hjust=1))

错误: “stat_count() 不得与 y 美学一起使用”。她能做些什么来纠正这个问题?

  1. 我应该删除 row.names — 它应该是 x = USArrests$State 吗??
  2. 我应该使用主题(axis.angle.x = 90)而不是当前主题吗?
  3. geom_histogram() 会比 Geom_bar 更好吗?
  4. 或者我应该使用 geom_col() 而不是 geom_bar()?

请建议正确的命令。谢谢

【问题讨论】:

  • 如果您认为您的问题已经解决,请检查是否已回答:)

标签: r geom-bar


【解决方案1】:

这是一个很常见的问题,请参阅this。只需使用geom_col 代替geom_bar,并将row.names 添加为新变量以避免进一步的问题:

USArrests$states <- row.names(USArrests)

ggplot(USArrests, aes(x = states, y = Murder)) + 
  geom_col() + 
  theme(axis.text.x=element_text(angle=90, hjust=1))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-19
    • 2019-06-22
    • 2013-11-23
    • 2021-07-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 2021-04-02
    相关资源
    最近更新 更多