如何在ggplot中绘制刻面饼图

时间:2017-06-21 10:20:25

标签: r

我在r

中有以下数据框
 Equipment       Area         Count
    RTG           1            12     
    RTG           2            13
    STS           1            34
    STS           2            33
    RTG           3            22
    STS           3            21

我想绘制带有设备的刻面饼图,并在饼图中计算nos。

我在R

中使用以下代码
ggplot(data = test) + 
geom_bar(aes(x = "", y = Count, fill = Area), 
stat = "identity") +
geom_text(aes(x = "", y = Count, label = count),position = 
position_fill(width=1))+
coord_polar(theta = "y") +
facet_grid(Equipment ~ ., scales = "free") 

但是,它不会产生任何图形。

1 个答案:

答案 0 :(得分:1)

ggplot(data = test, aes(x = "", y = Count, fill = Area)) + 
  geom_bar(stat = "identity") +
  geom_text(aes(label = Count), position = position_stack(vjust = 0.5)) +
  coord_polar(theta = "y") +
  facet_grid(Equipment ~ ., scales = "free")

enter image description here