Draw a pie or ring chart

ggpie.RdAggregate observations or nonnegative magnitudes by category. All display
labels are applied after aggregation. Each facet computes its own totals,
including facets added later with ggplot2::facet_wrap().
Usage
ggpie(
df,
.x,
.y = NULL,
.offset = 1,
.color = "white",
.legend = FALSE,
.label = TRUE,
.label_size = 3.5,
...,
hole = 0,
start = 0,
direction = 1,
order = "legacy",
label = "legacy",
label_position = c("inside", "outside"),
label_format = c("plain", "markdown", "formula"),
min_fraction = 0,
facet = NULL,
palette = NULL,
lang = NULL,
dictionary = NULL,
gap = 0,
explode = 0,
center_label = NULL,
center_format = c("plain", "markdown", "formula"),
check_overlap = FALSE
)Arguments
- df
A nonempty data frame with uniquely named columns.
- .x
A category column name supplied as a string.
- .y
Optional numeric weight column name supplied as a string. If omitted, each row contributes one.
- .offset
Positive multiplier for the default label radius.
- .color
Sector border colour.
- .legend
Show the legend.
- .label
Draw labels for visible sectors.
- .label_size
Label text size in millimetres.
- ...
Reserved for future named options. Must be empty.
- hole
Fraction of the radius occupied by the central hole.
- start
Starting angle in radians clockwise from 12 o'clock.
- direction
Use 1 for clockwise or -1 for counterclockwise.
- order
Sector order.
"levels"uses factor order or first appearance,"data"uses first appearance, and"legacy"reverses factor or sorted character levels. An explicit character vector specifies the order of IDs.- label
One of
"legacy"(name plus percentage),"count","percent","category", or a function returning a character vector from the per-pie sector table. The table includesslice,category_label,count_labelandpercent_labelas well as thestat_pie()variables.- label_position
Position of labels,
"inside"or"outside".- label_format
Sector text syntax:
"plain","markdown", or"formula"with a callback returning one checked plotmath string per sector.- min_fraction
Hide labels for slices below this fraction of their pie total. The slices remain in the statistical table.
- facet
Optional character vector of columns for
ggplot2::facet_wrap(). A local dictionary translates strip labels by column name after the original IDs have determined panels and their denominators.- palette
Optional vector of category colours. A named vector maps original category IDs to colours.
- lang
Optional language tag used to format computed display labels.
- dictionary
Optional local dictionary accepted by
forma_labels().- gap
Angular space in radians between adjacent sectors. The geom trims half the gap from each end. A sector no wider than the gap has no visible polygon. Statistical shares and angles use the untrimmed geometry.
- explode
Radial displacement of the sector in data units.
- center_label
Optional centre text. Use
"total"for the localised total, one literal string, or a callback returning a string for one pie. Callbacks have access tototal_label, the translated statistical termtotal_term, and the sector-level fields.- center_format
Centre text syntax:
"plain","markdown", or"formula". Supply an explicit formula for formula mode.- check_overlap
Hide overlapping sector labels within a panel using the device measurements and priority described in
geom_pie_label().
Examples
trips <- data.frame(mode = c("Cycle", "Walk", "Bus"), visits = c(12, 20, 18))
ggpie(trips, "mode", "visits", hole = 0.45, .legend = TRUE)