【发布时间】:2016-12-27 03:49:02
【问题描述】:
我的数据框看起来像
df
Group value
1 Positive 52
2 Negative 239
3 Neutral 9
我想使用 ggplot 制作数据框的饼图。
pie <- ggplot(df, aes(x="", y=value, fill=Group)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start=0)
这是我的饼图。
但是当我尝试在图表上添加百分比标签时
pie <- ggplot(df, aes(x="", y=value, fill=Group)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start=0) +
geom_text(aes(y = value/2 + c(0, cumsum(value)[-length(value)]),
label = percent(value/300 )), size=5)
这是我的结果。
我已经看到了许多与我相同的问题,即R + ggplot2 => add labels on facet pie chart ,但解决方案没有帮助。
【问题讨论】:
标签: r charts ggplot2 pie-chart