gpie: Pie or donut chart

View source: R/zzz-r4vn-graphs.R View source: R/graphs.R

gpieR Documentation

Pie or donut chart

Description

Draws the distribution of a categorical variable as a pie or donut chart. Bar charts are usually preferable when there are many categories.

Usage

gpie(
  data = NULL, x = NULL, vars = NULL, by = NULL, donut = FALSE, label = TRUE,
  percent = TRUE, digits = 1, xlab = NULL, title = NULL, subtitle = NULL,
  note = NULL, color = NULL, palette = "default", alpha = 1,
  border_color = "white", border_lwd = 1, clockwise = TRUE, missing = FALSE,
  missing_label = "Missing", theme = "journal", size = 11, combine = FALSE,
  ncol = NULL, file = NULL, width = 7, height = 5, dpi = 300, show = TRUE,
  bg = "white"
)

Arguments

data

A data frame. It may be omitted when an active R4VN data frame exists.

x

Categorical variable on the horizontal axis. Supply an unquoted name or a character name.

vars

Optional vars(...) selector used to request several variables in one call.

by

Optional grouping variable or hierarchical vars(...) specification.

donut

Draw a donut chart instead of a conventional pie.

label

Show category labels.

percent

Add percentages to labels.

digits

Number of percentage decimal places.

xlab

Optional category labels. Use an unnamed vector in displayed order or a named vector such as c(M = "Male", F = "Female").

title, subtitle, note

Main title, subtitle, and note.

color

A color name or vector of colors. When NULL, palette is used.

palette

One of "default", "journal", "blue", "green", "warm", "gray", or "colourblind"; alternatively, a color vector.

alpha

Color opacity from 0 to 1.

border_color, border_lwd

Slice-border colour and line width.

clockwise

Draw slices clockwise.

missing

Include missing x or by values as a category.

missing_label

Label used for missing values.

theme

Graph theme: "journal", "clean", "minimal", or "classic".

size

Base font size.

combine

When several graphs are produced, draw them as labelled panels in one figure.

ncol

Optional number of columns in a combined figure.

file

Optional output file ending in png, jpg, tiff, pdf, or svg.

width, height

Output width and height in inches.

dpi

Resolution for raster output.

show

Draw the graph in the current graphics device.

bg

Background color for exported files.

Details

Draws one or several categorical variables; by creates separate charts for group/stratum combinations.

Value

An object of class r4vn_graph; its data component contains counts and percentages.

Examples

d <- data.frame(group = c("A", "A", "B", "B", "B", "C"))
gpie(d, x = group)
gpie(d, x = group, donut = TRUE, palette = "journal")

# Extended usage examples

d <- data.frame(group = c("A", "A", "B", "B", "B", "C"))
gpie(d, x = group, show = FALSE)
gpie(d, x = group, donut = TRUE, palette = "journal", show = FALSE)
gpie(d, x = group, label = TRUE, percent = FALSE, show = FALSE)


R4VN documentation built on Sept. 30, 2026, 5:13 p.m.