用ggplot

时间:2016-09-25 13:27:50

标签: r ggplot2

我试图将两个因素(即计数)w.r.t的比例可视化为连续变量上的分箱。一个小的运行示例如下。

df <- data.frame(s=as.factor(c("0","1","1","0","1","0","0")),
                 density=c(1.1,1.3,1.4,2.1,2.3,2.2,2.4),
                 n=as.factor(c("A","A","A","A","A","A","A")))

ggplot(df, aes(x = density, fill = s)) + 
  geom_histogram(position = "stack", bins = 2) + 
  facet_wrap("n", scales = "free")

产生以下情节:

Simple histogram with a fill by factor

现在我想要的是,而不是绝对计数,我在y轴上获得百分比,其中100%是记录总数,填充表示因子级别0涵盖了多少百分比以及如何许多因素为1级。

0 个答案:

没有答案