我的数据如下:
fifa_data %>% count(Nationality) %>% mutate(n=n/sum(n))
我想将这些数字绘制在饼图中,然后将百分比作为标签放入饼的每个扇区中。但是,我要做的就是这样:
使用此代码:
fifa_data %>% count(Nationality) %>%
mutate(n=n/sum(n)) %>%
ggplot( aes(x="", y=n, fill=Nationality))+
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start=0) +
geom_text(aes(y = n, label = percent(n)), size=3)