【发布时间】:2019-10-17 06:01:36
【问题描述】:
我想在 R 中创建一个比例条形图。我有两个变量,一个是“醉酒”,一个是“住房”。我想绘制每个“住房”类别中满足的人的比例“喝醉了”。
数据框如下所示:
醉酒:0、1、0、1、1、1、1、0 外壳:1、2、1、3、1、4、1、1
我想知道如何绘制每种住房类别(1 到 4)中满足“1”的醉酒比例。
png("Graphs/Analysis_Figure1.png")
分析%>%
计数(住房,醉酒)%>%
group_by(住房) %>%
变异(频率 = n/sum(n)) %>%
ggplot(aes(x = 住房,y = 频率,填充 = 醉酒)) +
geom_bar(stat="identity", position = 'dodge')
dev.off()
这给了我比例,但不是只包括醉酒的“1”回答,我还得到“0”。有没有办法只包含 1?
This is an image I generated with STATA, which I hope to replicate inN R
This is what I get with R instead. I want to remove the "2 or less" (coded as "0" drunk responses
【问题讨论】:
标签: r