Display frequency instead of count with geom_bar() in ggplot

前端 未结 2 1259
别跟我提以往
别跟我提以往 2020-12-10 10:33

On this page, they give the following example

library(ggplot2)
library(reshape2)
ggplot(data=tips, aes(x=day)) + geom_bar(stat=\"bin\")

Ins

相关标签:
2条回答
  • 2020-12-10 11:12

    Here's the solution which can be found in related question:

    pp <- ggplot(data=tips, aes(x=day)) + 
          geom_bar(aes(y = (..count..)/sum(..count..)))
    

    If you would like to label frequencies as percentage, add this (see here):

    library(scales)
    pp + scale_y_continuous(labels = percent)
    
    0 讨论(0)
  • 2020-12-10 11:17

    now ..prop.. is available

    ggplot(data=tips, aes(x=day)) + 
      geom_bar(aes(y = ..prop.., group = 1))
    
    0 讨论(0)
提交回复
热议问题