# 准备数据
df <- data.frame(
group = c("Male", "Female", "Child"),
value = c(10, 20, 30))
ggpie(df, "value",
label = "group", # 标签
fill = "group",
color = "white", # 图片轮廓颜色
palette = c("#00AFBB", "#E7B800", "#FC4E07") )
ggdonutchart(df, "value",
label = "group",
fill = "group",
color = "white",
palette = c("#00AFBB", "#E7B800", "#FC4E07")
)
df$percent_value = round(df$value/sum(df$value) * 100)
labs <- paste0(df$group, " (", df$percent_value, "%)")
ggpie(df, "value",
label = labs,
fill = "group",
color = "white",
palette = c("#00AFBB", "#E7B800", "#FC4E07"))
ggdonutchart(df, "value",
label = labs,
fill = "group",
color = "white",
palette = c("#00AFBB", "#E7B800", "#FC4E07"))
ggpie(df, "value",
label = labs,
lab.pos = "in", # 标签在饼图内部
lab.font = "white", # 标签颜色为白色
fill = "group",
color = "white",
palette = c("#00AFBB", "#E7B800", "#FC4E07"))
ggdonutchart(df, "value",
label = labs,
lab.pos = "in",
lab.font = "white",
fill = "group",
color = "white",
palette = c("#00AFBB", "#E7B800", "#FC4E07"))
本博客内容将同步更新到个人微信公众号:生信玩家。欢迎大家关注~~~