Obtaining Percent Scales Reflective of Individual Facets with ggplot2

后端 未结 2 1708
深忆病人
深忆病人 2020-12-17 01:29

So I managed to get this far...

ggplot(init, aes(x=factor(ANGLE), fill=NETWORK)) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
facet_wrap(~SHOW) + opts(         


        
相关标签:
2条回答
  • 2020-12-17 02:08

    Using the ..density.. stat rather than ..count.. seems to work for me:

    ggplot(dat, aes(x=factor(ANGLE))) +
     geom_bar(aes(y = ..density..,group = SHOW,fill = NETWORK)) +
     facet_wrap(~SHOW) + 
     opts(legend.position = "top") +
     scale_y_continuous(labels = percent_format())
    

    At least, this produces a different result, I can't say for sure it reflects what you want. Additionally, I'm not sure why the ..count.. stat was behaving that way.

    enter image description here

    0 讨论(0)
  • 2020-12-17 02:17

    this is no longer working in newer versions of ggplot. The way to do it is now + stat_count(aes(y=..prop..))

    0 讨论(0)
提交回复
热议问题