r - 在 ggplot 条形图中按组标准化
问题描述
我遇到了与此问题中描述的相同的问题:ggplot 中的标准化条形高度(我将其作为一个新问题发布,因为我的声誉太低而无法发表评论。)我希望蓝色条形整合到 1 和红色条形以及,我认为这是公认的答案所提供的。但这对我不起作用,因为我收到此错误:
Aesthetics must be valid computed stats. Problematic aesthetic(s): y = ..density...
Did you map your stat in the wrong layer?
当我完全按照 vpipkt 的建议做时:
ggplot(dat, aes(x = bin, y = ..density.., group = source, fill = source)) +
geom_bar(alpha = 0.5, position = 'identity')
使用 user3396385 提供的示例数据:
set.seed(47)
BG.restricted.hs = round(runif(100, min = 47, max = 1660380))
FG.hs = round(runif(1000, min = 0, max = 1820786))
dat = data.frame(x = c(BG.restricted.hs, FG.hs),
source = c(rep("BG", length(BG.restricted.hs)),
rep("FG", length(FG.hs))))
dat$bin = cut(dat$x, breaks = 200)
但是,使用..count..
而不是..density..
没有错误:
ggplot(dat, aes(x = bin, y = ..count.., group = source, fill = source)) +
geom_bar(alpha = 0.5, position = 'identity')
但它与原始问题中的示例存在相同的问题,整体权重计数较少的数据集不太明显。既然答案被接受了,我认为它一定在某个时候起作用了......从那时起有什么想法可能出了问题吗?如果有人能告诉我他们是否有同样的问题,我会很高兴。感谢您的任何帮助 :)
解决方案
推荐阅读
- google-apps-script - 如何单步执行谷歌脚本
- keras - 问题合并 LSTM Seq2Seq 模型中的两层以用于问答用例
- html - 在视频上叠加文字
- json - 如何访问单个 JSON API 项?(Python 3.6)
- javascript - javascript 集合 - 向集合内对象中的数组添加值
- php - TYPO3:从另一个扩展覆盖 TCA 后端类公共变量
- mysql - Node Js在Firebase中发送通知之前查询MySql
- python - Python列表理解太慢了
- angular - Angular 6:Http升级
- c++ - “'CLOCK_PER_SEC' 未在此范围内声明”错误,即使包含