加載需要使用的R包
library(ggplot2)
library(ggpie)
library(ggpubr)
library(patchwork)
ggpie繪制餅圖
基本的餅圖
## 使用diamonds數(shù)據(jù)集
head(diamonds)
## 基本的餅圖
ggpie::ggpie(data = diamonds, group_key = "cut",
count_type = "full", ## 設(shè)置未count時需要有名字為count的列(數(shù)值型)
label_info = "all", # 標(biāo)簽內(nèi)容:默認(rèn)"count", "ratio", "all"
label_type = "horizon", # 標(biāo)簽形式:"none", "circle", "horizon"
label_split = NULL,
label_size = 4,
label_pos = "in",# 超過閾值的標(biāo)簽在內(nèi)部
label_threshold = 25) # 設(shè)置閾值
中間為空心的餅圖
## 中間為空心的餅圖
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,# 設(shè)置內(nèi)層環(huán)形的閾值
inner_label_size = 2,
outer_label_type = "circle", # 設(shè)置外層環(huán)形
outer_label_pos = "in",
小遺憾,沒有參數(shù)可以顯示每個部分對應(yīng)的名稱畜隶,如Ideal壁肋、Good等
繪圖很方便,還可以直接計算比例并標(biāo)注