加载需要使用的R包
library(ggplot2)
library(ggpie)
library(ggpubr)
library(patchwork)
ggpie绘制饼图
基本的饼图
## 使用diamonds数据集
head(diamonds)
## 基本的饼图
ggpie::ggpie(data = diamonds, group_key = "cut",
count_type = "full", ## 设置未count时需要有名字为count的列(数值型)
label_info = "all", # 标签内容:默认"count", "ratio", "all"
label_type = "horizon", # 标签形式:"none", "circle", "horizon"
label_split = NULL,
label_size = 4,
label_pos = "in",# 超过阈值的标签在内部
label_threshold = 25) # 设置阈值
中间为空心的饼图
## 中间为空心的饼图
ggdonut(data = diamonds, group_key = "cut", count_type = "full",
label_info = "all",
label_type = "circle",
label_split = NULL,
label_size = 4,
label_pos = "in")
中间有两个圈的饼图
ggnestedpie(data = diamonds, group_key = c("cut", "color"), count_type = "full",
inner_label_info = "all",
inner_label_split = NULL,
inner_label_threshold = 3,# 设置内层环形的阈值
inner_label_size = 2,
outer_label_type = "circle", # 设置外层环形
outer_label_pos = "in",
小遗憾,没有参数可以显示每个部分对应的名称,如Ideal、Good等
绘图很方便,还可以直接计算比例并标注