ggplot显示合并统计信息,而不是变量的摘要分类

时间:2019-07-14 04:45:32

标签: r ggplot2 geom-bar

ggplot不会显示变量的完整摘要/分组统计信息,而是显示变量的合并数字(即总数)。

我尝试谷歌搜索和研究无济于事。

mydatawlocation %>% 
  group_by(`General Location`) %>% 
  summarise(count_level = n()) %>% 
  ggplot(aes(x = as.factor('General Location'), y = count_level)) +
  geom_bar(stat = 'identity')

General Location变量具有多个位置,例如“东”,“西”。我想得到每个(东/西/等)的总计数明细。相反,我的代码在x轴上搅动了“常规位置”,在y轴上搅动了总计数,

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

mydatawlocation %>% 
group_by(`General Location`) %>% 
summarise(count_level = n()) %>% 
ggplot(aes(x = as.factor(`General Location`), y = count_level)) +
geom_bar(stat = 'identity')

我已替换

as.factor('General Location')  # using '' 

as.factor(`General Location`) # using ``
相关问题