df <- data.frame(
group = c("Female", "Male", "Child"),
number = c(25, 30, 45)
)
df$percent_value = round(df$number/sum(df$number) * 100)
df$percent_value <- paste0(df$percent_value, "%")
df$cs <- rev(cumsum(rev(df$number)))
df$pos <- df$number/2 + dplyr::lead(df$cs, 1, default = 0)
ggplot(df, aes(x=2, y=number, fill=forcats::fct_inorder(group)))+
geom_bar(width=0.3, stat="identity") +
coord_polar("y", start=0) +
xlim(.2,2.5) +
ggsci::scale_fill_npg() +
theme_void() +
geom_text(aes(y=pos,label=percent_value), size=5, col="black") +
guides(fill=guide_legend(title=NULL))
成图
Rplots.png
网友评论