| RingPlotAtomic | R Documentation |
Core implementation for drawing a single ring (multi-layer donut) plot.
This is the workhorse behind the exported RingPlot function —
it takes a single data frame (no split_by support) and returns a
ggplot object. Each level of x becomes a concentric ring,
and within each ring the group_by variable divides the ring into
filled segments drawn via geom_col() with coord_polar("y").
When y = NULL, the count of observations per combination is used.
y-values are always normalised to proportions (0–1) within each
(x, facet_by) group so that each complete ring sums to 1.
RingPlotAtomic(
data,
x = NULL,
y = NULL,
group_by = NULL,
group_by_sep = "_",
group_name = NULL,
label = NULL,
clockwise = TRUE,
keep_na = FALSE,
keep_empty = FALSE,
facet_by = NULL,
facet_scales = "free_y",
facet_ncol = NULL,
facet_nrow = NULL,
facet_byrow = TRUE,
theme = "theme_this",
theme_args = list(),
palette = "Paired",
palcolor = NULL,
palreverse = FALSE,
alpha = 1,
aspect.ratio = 1,
legend.position = "right",
legend.direction = "vertical",
title = NULL,
subtitle = NULL,
xlab = NULL,
ylab = NULL,
seed = 8525,
...
)
data |
A data frame. |
x |
A character string specifying the column to define the rings
(concentric layers) of the plot. Each unique value becomes one ring.
When |
y |
A character string specifying the numeric column for segment
sizing. When |
group_by |
A character vector of column names to divide each ring
into filled segments. Each unique combination becomes one segment per
ring. Multiple columns are concatenated with |
group_by_sep |
A character string to join multiple |
group_name |
A character string used as the fill legend title.
When |
label |
A logical value controlling whether ring labels are shown.
Labels display the |
clockwise |
A logical value. When |
keep_na |
A logical value or a character to replace the NA values in the data.
It can also take a named list to specify different behavior for different columns.
If TRUE or NA, NA values will be replaced with NA.
If FALSE, NA values will be removed from the data before plotting.
If a character string is provided, NA values will be replaced with the provided string.
If a named vector/list is provided, the names should be the column names to apply the behavior to,
and the values should be one of TRUE, FALSE, or a character string.
Without a named vector/list, the behavior applies to categorical/character columns used on the plot,
for example, the |
keep_empty |
One of FALSE, TRUE and "level". It can also take a named list to specify
different behavior for different columns. Without a named list, the behavior applies to the
categorical/character columns used on the plot, for example, the
|
facet_by |
A character string specifying the column name of the data frame to facet the plot.
Otherwise, the data will be split by |
facet_scales |
Whether to scale the axes of facets. Default is "fixed"
Other options are "free", "free_x", "free_y". See |
facet_ncol |
A numeric value specifying the number of columns in the facet. When facet_by is a single column and facet_wrap is used. |
facet_nrow |
A numeric value specifying the number of rows in the facet. When facet_by is a single column and facet_wrap is used. |
facet_byrow |
A logical value indicating whether to fill the plots by row. Default is TRUE. |
theme |
A character string or a theme class (i.e. ggplot2::theme_classic) specifying the theme to use. Default is "theme_this". |
theme_args |
A list of arguments to pass to the theme function. |
palette |
A character string specifying the palette to use.
A named list or vector can be used to specify the palettes for different |
palcolor |
A character string specifying the color to use in the palette.
A named list can be used to specify the colors for different |
palreverse |
A logical value indicating whether to reverse the palette. Default is FALSE. |
alpha |
A numeric value specifying the transparency of the plot. |
aspect.ratio |
A numeric value specifying the aspect ratio of the plot. |
legend.position |
A character string specifying the position of the legend.
if |
legend.direction |
A character string specifying the direction of the legend. |
title |
A character string specifying the title of the plot. A function can be used to generate the title based on the default title. This is useful when split_by is used and the title needs to be dynamic. |
subtitle |
A character string specifying the subtitle of the plot. |
xlab |
A character string specifying the x-axis label. |
ylab |
A character string specifying the y-axis label. |
seed |
The random seed to use. Default is 8525. |
... |
Additional arguments. |
A ggplot object with height and width
attributes (in inches) attached.
Column resolution — x, group_by, y,
and facet_by are validated and transformed via
check_columns. If x is NULL, a dummy
.x column (value 1) is created, producing a single-ring
(pie-chart-like) plot. If group_by is NULL, a dummy
.group_by factor is created and the legend is suppressed.
Multi-column group_by inputs are concatenated with
group_by_sep.
NA / empty-level handling — process_keep_na_empty()
applies keep_na and keep_empty policies. Per-column
keep_empty settings are extracted for x,
group_by, and facet_by independently. The facet
columns must have identical keep_empty values.
Count aggregation — when y = NULL, the count of
observations in each unique (x, group_by,
facet_by) combination is computed as a new .y column.
Factor levels are preserved after aggregation.
Proportion scaling — y-values are divided by the sum within
each (x, facet_by) group, normalising each ring to
sum to 1.0. This is essential for polar coordinates where each ring
represents a full 360 degrees.
Ring resolution — The levels of x are reversed so
the outermost ring appears first in the data (rings are drawn
outward from the origin). NA levels are appended.
Label logic — When label = NULL, labels are
automatically suppressed for single-ring plots and shown for
multi-ring plots. Labels are placed at the inner edge of each ring
via geom_label().
Clockwise ordering — When clockwise = TRUE (default),
the group_by levels are reversed so segments appear clockwise
from the top. The legend guide also reverses its order.
Colour mapping — palette_this() assigns
colours to all group_by levels, including NA
(defaulting to "grey80").
Plot assembly — The ggplot object is built with
geom_col() (ring segments), coord_polar("y") (polar
transform), scale_x_discrete() (with a leading space level
as the donut hole), and scale_fill_manual() with per-group
colours. All axes, ticks, grid lines, and panel borders are removed
for a clean appearance. The fill scale drop argument is
controlled by keep_empty_group.
Dimension calculation — calculate_plot_dimensions()
computes plot height and width from aspect.ratio and legend
metrics. The resulting height / width attributes are
stored on the ggplot object.
Faceting — facet_plot() wraps the plot with
facet_wrap / facet_grid if facet_by is
provided, respecting the keep_empty setting for facet
variables.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.