| RadarPlotAtomic | R Documentation |
Core implementation for drawing a single radar (or spider) chart. This
is the workhorse behind the exported RadarPlot and
SpiderPlot functions — it takes a single data frame
(no split_by support) and returns a ggplot object.
Radar charts display multivariate data on a two-dimensional polar
coordinate system where each variable (x-axis category) is placed
along a radial axis evenly spaced around the circle. The data values
are connected by lines forming a polygon (or multiple polygons when
group_by is provided). When polygon = FALSE (the
default) the grid is rendered as concentric circles (classic radar
chart); when polygon = TRUE straight polygonal grid lines are
used (spider chart variant).
The polar coordinate system is implemented via a local
coord_radar() helper that extends
ggplot2::CoordPolar with is_linear = TRUE, allowing
discrete x-axis positions to be mapped to evenly spaced angular
coordinates.
RadarPlotAtomic(
data,
x,
x_sep = "_",
group_by = NULL,
group_by_sep = "_",
y = NULL,
group_name = NULL,
groups = NULL,
scale_y = c("group", "global", "x", "none"),
y_min = 0,
y_max = NULL,
y_nbreaks = 4,
polygon = FALSE,
fill = TRUE,
linewidth = 1,
pt_size = 4,
max_charwidth = 16,
bg_color = "grey80",
bg_alpha = 0.1,
theme = "theme_this",
theme_args = list(),
palette = "Paired",
palcolor = NULL,
palreverse = FALSE,
facet_by = NULL,
facet_scales = "fixed",
facet_ncol = NULL,
facet_nrow = NULL,
facet_byrow = TRUE,
alpha = 0.2,
aspect.ratio = 1,
legend.position = waiver(),
legend.direction = "vertical",
keep_na = FALSE,
keep_empty = FALSE,
title = NULL,
subtitle = NULL,
...
)
data |
A data frame. |
x |
A character string specifying the column name of the data
frame to plot on the x-axis (the radial categories). Must be
character or factor. Multiple columns can be provided; they are
concatenated with |
x_sep |
A character string used to join multiple |
group_by |
A character vector of column names to group the
data into separate filled polygons. Each unique combination
becomes a distinct polygon layer. Multiple columns are
concatenated with |
group_by_sep |
A character string used to join multiple
|
y |
A character string specifying the numeric column for the
radial axis. When |
group_name |
A character string used as the colour/fill legend
title. When |
groups |
A character vector of group values (in the
|
scale_y |
How should the radial axis be scaled? Default is
|
y_min |
A numeric value setting the minimum of the radial
axis. Default |
y_max |
A numeric value setting the maximum of the radial
axis. When |
y_nbreaks |
A numeric value for the number of breaks
(concentric grid lines) on the radial axis. Default |
polygon |
A logical value. When |
fill |
A logical value. When |
linewidth |
A numeric value for the width of the polygon
outline lines. Default |
pt_size |
A numeric value for the size of the data point
markers. Default |
max_charwidth |
A numeric value for the maximum character
width of x-axis labels before wrapping. Default |
bg_color |
A character string specifying the background fill
colour. Default |
bg_alpha |
A numeric value for the transparency of the
background fill. Default |
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. |
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. |
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. |
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
|
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. |
... |
Additional arguments. |
A ggplot object with height and width
attributes (in inches) attached.
Column resolution — x, y,
group_by, and facet_by are validated and
transformed via check_columns. Multi-column
inputs for x and group_by are concatenated
using x_sep and group_by_sep.
Group setup — When group_by is NULL,
a dummy .group factor is created so polygons still
draw. The legend is suppressed. When groups is
provided, data is filtered to only those group levels.
Count aggregation — When y = NULL, the count
of observations in each unique (x, group_by,
facet_by) combination is computed. Factor levels
are preserved after aggregation.
Proportion scaling — The scale_y argument
controls y-value normalisation: "group" scales within
each group, "global" within each facet (or the whole
dataset), "x" within each x category, and
"none" leaves values raw. Percent labels are used
for scaled modes.
NA / empty-level handling —
process_keep_na_empty() applies keep_na
and keep_empty policies. Per-column keep_empty
settings for x, group_by, and facet_by
are extracted; facet columns must share the same value.
Coordinate setup — The local coord_radar()
creates a CoordPolar subclass with
is_linear = TRUE, placing discrete x positions at
evenly spaced angles.
Y-axis range — y_min, y_max, and
y_nbreaks determine the radial axis limits and
the number of concentric grid lines.
Colour mapping — palette_this()
assigns colours to all group_by levels, including
NA (defaulting to "grey80").
Background layer — When polygon = TRUE, a
polygonal background fills the area between y_min and
y_max. When polygon = FALSE, a smooth circular
background is interpolated via 360 sample points.
Radial grid lines — geom_path() draws
radial lines from y_min to y_max at each
x-axis position, respecting facets.
Polygon grid — When polygon = TRUE,
concentric polygonal grid lines are drawn at each break
level via geom_polygon().
Data rendering — geom_polygon() draws the
filled (or unfilled) polygons for each group.
geom_point() adds points at each observation.
Radial axis labels are rendered as text at a fixed
angular offset.
Scale configuration — scale_y_continuous()
sets the radial axis limits and breaks.
scale_x_discrete() positions the category labels.
Colour scales use scale_fill_manual() and
scale_color_manual() with drop controlled
by keep_empty_group.
Circular grid lines — When polygon = FALSE,
dashed circular grid lines are styled via
panel.grid.major.y.
Dimension calculation —
calculate_plot_dimensions() computes plot
height and width from aspect.ratio, legend metrics,
and a base height.
Faceting — facet_plot() wraps the
plot with facet_wrap / facet_grid if
facet_by is supplied, 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.