R-可视化(五):饼图/圆环图

# 准备数据
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") )

R-可视化(五):饼图/圆环图_第1张图片

ggdonutchart(df, "value",
             label = "group",                               
             fill = "group",                            
             color = "white",                                
             palette = c("#00AFBB", "#E7B800", "#FC4E07") 
)

R-可视化(五):饼图/圆环图_第2张图片

  • 改变标签
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"))

R-可视化(五):饼图/圆环图_第3张图片

ggdonutchart(df, "value",
             label = labs,
             fill = "group",
             color = "white",
             palette = c("#00AFBB", "#E7B800", "#FC4E07"))

R-可视化(五):饼图/圆环图_第4张图片

  • 改变标签位置和颜色
ggpie(df, "value",
      label = labs,
      lab.pos = "in",                               # 标签在饼图内部
      lab.font = "white",                           # 标签颜色为白色
      fill = "group",
      color = "white",
      palette = c("#00AFBB", "#E7B800", "#FC4E07"))

R-可视化(五):饼图/圆环图_第5张图片

ggdonutchart(df, "value",
             label = labs,
             lab.pos = "in",                                
             lab.font = "white",                            
             fill = "group",
             color = "white",
             palette = c("#00AFBB", "#E7B800", "#FC4E07")) 

R-可视化(五):饼图/圆环图_第6张图片
本博客内容将同步更新到个人微信公众号生信玩家。欢迎大家关注~~~
在这里插入图片描述

你可能感兴趣的:(R-可视化)