我有一个数据框df:
> head(df,20)
Stakeholder Response
1 Consumers Very effective
2 Consumers Effective
3 Consumers Effective
4 Consumers I don't know
5 Consumers Slightly effective
6 Consumers Not effective at all
7 Experts Very effective
8 Experts Effective
9 Experts I don't know
10 Experts Slightly effective
11 Experts Not effective at all
12 Experts Not effective at all
13 Experts Not effective at all
14 Consumers I don't know
15 Experts Effective
16 Consumers Very effective
17 Consumers Very effective
18 Consumers Slightly effective
19 Experts Effective
20 Experts Slightly effective
我要与之密谋
ggplot(df, aes(Stakeholder)) +
geom_bar(aes(y = (..count..)/sum(..count..), fill = Response), width = 0.7, position="fill") +
scale_y_continuous(labels = scales::percent) +
coord_flip()
那给了我
如何将每个响应的百分比添加到图表?
这是我制作的图表的类似示例,但我想在其中添加百分比ggplot replace count with percentage in geom_bar
我的问题与此R - Aggregate Percentage for Stacked Bar Charts using ggplot2有所不同,因为我的数据框是分类数据。