使用ggplot2获得单个分面的反射比例百分比 [英] Obtaining Percent Scales Reflective of Individual Facets with ggplot2

查看:154
本文介绍了使用ggplot2获得单个分面的反射比例百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ggplot(init,aes(x = factor(ANGLE),填充= NETWORK))+ 
geom_bar(aes(y =(..count ..)/ sum(.. count ..)))+
facet_wrap(〜SHOW)+ opts(legend.position =top)+
scale_y_continuous(labels = percent_format())

我的问题是下面的彩色条代表我研究中所有电视节目的全部相机ANGLE测量值的百分比。例如,OREILLY图形中的ANGLE 2的条码接近15%,对于图表中的所有ANGLE测量,该值为15%,而不仅仅是OREILLY方面的那些。我想让每个图表显示的是相对于一个电视节目(仅仅是这一个方面)的计数的百分比,而不是所有这些。

这个想法是比较不同节目中摄像机角度的比例使用情况,但是与现在的图形方式相比,倾斜使具有更多摄像机角度变化的节目看起来好像他们在摄像机角度2花费的时间比实际上相对于其他令人沮丧的。



令人沮丧的是,我花了一个小时让它看起来像我想要的样子,然后我犯了更新R的错误。随着它的更新,这发生了。



缩小的数据表是在这里可用



编辑:这也行不通。我试图把group = NETWORK放在aes(...)的两个(和两个)中,但没有任何改变。我也尝试过与group = SHOW相同的东西,我认为可能有更多的机会,因为我想在每个方面只获得一个SHOW的百分比(因此,每个方面的比例应该上升到大约80因为很多节目主要是相机角度2)。我错过了什么?

  ggplot(init,aes(x =因子(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())

< img src =https://i.stack.imgur.com/UrbKm.pngalt =有问题的图形>

解决方案

使用 .. density .. stat而不是 .. count .. 似乎适用于我:

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

至少,这会产生不同的结果,我不能肯定地说它反映了您想。另外,我不确定为什么 .. count .. stat是这样做的。




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 colored bars below represent the percent of ALL the camera ANGLE measurements for all the television programs in my study. For instance, the OREILLY graph has a bar that approaches 15% for ANGLE 2, which is %15 for all the ANGLE measurements in the chart, not solely those in the OREILLY facet. What I want each graph to show is the percentage of counts relative to just ONE television show (just that one facet), rather than all of them.

The idea is to compare the proportional use of camera angles among different shows, but with the way the graph is now, it is skewed to make the shows with more camera angle changes look as though they spend way more time at camera angle 2 than they actually do relative to the others.

The frustrating part of it all is that I spent an hour getting this to look the way I wanted, then I made the mistake of updating R. The packages updated along with it, and this happened.

A reduced size data table is available here.

EDIT: This doesn't work either. I tried putting "group=NETWORK" in either (and both) of the aes(..., ) terms, but nothing changed. I also tried the same thing with "group=SHOW", which I thought might have more of a chance since I wanted to get just one percentages for one SHOW in each facet (hence, the scales for each facet should go up to about 80% since so many of the shows are predominantly camera angle 2). Am I missing 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())

解决方案

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.

这篇关于使用ggplot2获得单个分面的反射比例百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆