pie_chart: Create Pie or Donut Charts

View source: R/percent_bar.R

pie_chartR Documentation

Create Pie or Donut Charts

Description

Generates a pie chart or donut chart from input data.

Usage

pie_chart(
  input,
  var,
  var2 = NULL,
  type = 2,
  show_freq = FALSE,
  color = NULL,
  palette = "jama",
  title = NULL,
  text_size = 10,
  title_size = 20,
  add_sum = FALSE
)

Arguments

input

Input dataframe.

var

Variable for the chart.

var2

Secondary variable for donut chart (type = 3).

type

Chart type: 1 (pie), 2 (donut), 3 (PieDonut via webr).

show_freq

Logical to show frequencies. Default is FALSE.

color

Optional color palette.

palette

Color palette name. Default is "jama".

title

Plot title. Default is NULL.

text_size

Text size. Default is 10.

title_size

Title size. Default is 20.

add_sum

Logical to add sum to labels. Default is FALSE.

Value

A ggplot object.

Author(s)

Dongqiang Zeng

Examples

# Simulate data
set.seed(123)
sim_data <- data.frame(
  Subtype = sample(c("EBV", "GS", "MSI", "CIN"), 100, replace = TRUE)
)

# Create pie chart
p1 <- pie_chart(input = sim_data, var = "Subtype", palette = "jama")
if (!is.null(p1)) print(p1)

# Create donut chart
p2 <- pie_chart(input = sim_data, var = "Subtype", type = 2)
if (!is.null(p2)) print(p2)

IOBR documentation built on May 30, 2026, 5:07 p.m.