Plot relative frequencies with dodged bar plots in ggplot2

后端 未结 1 1871
日久生厌
日久生厌 2021-01-21 20:35

can anybody answer how I can plot a bar-plot which maps a numeric x-variable to its relative frequency grouped by a factor in ggplot2? The important thing is: The relative frequ

相关标签:
1条回答
  • 2021-01-21 21:27

    I was facing the same problem as yours and I figured it out: instead of plotting ..count../sum(..count..), plot ..density..*your_binwidth Indeed, the ..density.. variable created by the bin stat is basically equal to proportion/bindwidth. Your code becomes:

    p + stat_bin(aes(y=..density..*0.2), position='dodge', binwidth=0.2)
    
    0 讨论(0)
提交回复
热议问题