Getting percentage scales reflecting individual faces with ggplot2

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(legend.position = "top") + scale_y_continuous(labels = percent_format()) 

My problem is that the color bars below represent the percentage of ALL ANGLE camera measurements for all television programs in my study. For example, the OREILLY graph has a bar that approaches 15% for ANGLE 2, which is% 15 for all ANGLE dimensions in the diagram, and not just for OREILLY faces. What I want each chart to show is the percentage of counts relative to only one television show (only this one aspect), and not all of them.

The idea is to compare the proportional use of camera angles among different shows, but given how the chart is now, it is distorted to make shows with a large change in camera angle, as if they spend more time on camera angle 2 than they actually refer to others.

The disgusting part of all of this is that I spent an hour making it look the way I wanted, then I made a mistake updating R. Updated packages along with it, and it happened.

Reduced data table is available here .

EDIT : this doesn't work either. I tried putting "group = NETWORK" in (or both) of the aes (...,) members, but nothing changed. I also tried the same thing with "group = SHOW", which I thought could have a better chance, since I wanted to get only one percent for one SHOW in each aspect (therefore, the scales for each face should increase to about 80 %, since many of the shows have mainly a camera angle 2). Did I miss something?

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

Problematic Graphic

+6
source share
2 answers

Using stat ..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 gives a different result, I can’t say for sure that it reflects what you want. Also, I'm not sure why stat ..count.. behaved this way.

enter image description here

+4
source

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

0
source

Source: https://habr.com/ru/post/910229/


All Articles