Show percent % instead of counts in charts of categorical variables

前端 未结 8 2501
梦如初夏
梦如初夏 2020-11-22 06:06

I\'m plotting a categorical variable and instead of showing the counts for each category value.

I\'m looking for a way to get ggplot to display the perc

8条回答
  •  轮回少年
    2020-11-22 06:32

    As of March 2017, with ggplot2 2.2.1 I think the best solution is explained in Hadley Wickham's R for data science book:

    ggplot(mydataf) + stat_count(mapping = aes(x=foo, y=..prop.., group=1))
    

    stat_count computes two variables: count is used by default, but you can choose to use prop which shows proportions.

提交回复
热议问题