【发布时间】:2017-12-27 19:58:30
【问题描述】:
我创建了一个包含 1 列值计数的列表:
ataques_tot <- count(t1$attacktype1_txt)
ataques_tot
x freq
1 Armed Assault 40223
2 Assassination 18402
3 Bombing/Explosion 83073
4 Facility/Infrastructure Attack 9581
5 Hijacking 11733
6 Unarmed Assault 913
7 Unknown 6425
我想用百分比而不是计数来制作饼图。我试图将该列表带到 df,然后使用类似这样的东西:
ggpie(ataques_tot, "value", label = "group",
fill = "group", color = "white")
但我很挣扎,也许这个选项已经在 ggplot2 上实现了......
我也试过这个:
pie <- ggplot(t1, aes(x = factor(1), fill = factor(attacktype1_txt))) +
geom_bar(width = 1)
pie + coord_polar(theta = "y")
但它给了我一个计数,而不是分类变量的百分比。之后,我只需要为情节命名即可。
【问题讨论】:
标签: r dataframe ggplot2 pie-chart