【发布时间】:2020-03-02 17:26:30
【问题描述】:
如何向此堆叠条形图添加百分比标签,堆叠条的每个组件都标有相应的百分比?
ggplot(mtcars, aes(cyl, fill = factor(gear))) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent)
编辑: 能够添加计数,但仍然无法将其转换为百分比
ggplot(mtcars, aes(cyl, fill = factor(gear))) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent)+
geom_text(aes(label=stat(count)), stat='count', position='fill')
【问题讨论】:
-
提供的代码在我的 y 轴上有百分比标签。
-
为澄清而编辑:如何向此堆叠条形图添加百分比标签,堆叠条的每个组件都标有相应的百分比?