
Plot a spider chart across continuous and binary variables
Source:R/PlotSpiderChart.R
PlotSpiderChart.RdThis function summarizes a set of variables and displays them on a spider
chart. Continuous variables are plotted as mean z-scores by default using
CreateZScoreObject(), while binary variables are plotted as percentages. It can
overlay groups on one spider chart or facet by group, optionally fill the
polygons, relabel spokes using variable labels, wrap long labels, reorder
variables to visually emphasize between-group differences, and optionally
return an interactive radar chart using plotly.
Usage
PlotSpiderChart(
data,
variables,
group_var = NULL,
Relabel = TRUE,
ContinuousSummary = "mean",
ContinuousScaling = "zscore",
Fill = FALSE,
FillAlpha = 0.2,
Facet = FALSE,
VariableOrder = "input",
VariableCategories = NULL,
BinaryPositiveValue = 1,
Palette = NULL,
LineSize = 1,
PointSize = 2,
ShowPoints = FALSE,
LegendTitle = NULL,
PlotTitle = NULL,
Subtitle = NULL,
Caption = NULL,
AxisLabelSize = 12,
AxisTextSize = 10,
StripTextSize = 11,
WrapLabels = TRUE,
LabelWrapWidth = 22,
LabelRadiusMultiplier = 1.22,
PlotMarginTop = 40,
PlotMarginRight = 120,
PlotMarginBottom = 40,
PlotMarginLeft = 120,
interactive = FALSE,
InteractiveHeight = 700,
InteractiveWidth = NULL,
InteractiveAxisMin = NULL,
InteractiveAxisMax = NULL,
tooltip_digits = 2,
Data = lifecycle::deprecated(),
Variables = lifecycle::deprecated(),
GroupVariable = lifecycle::deprecated(),
TooltipDigits = lifecycle::deprecated(),
MakeInteractive = lifecycle::deprecated()
)Arguments
- data
A data frame.
- variables
Character vector of variable names to plot.
- group_var
Optional grouping variable name. If NULL, one overall summary profile is plotted.
- Relabel
Logical; if TRUE, use variable labels when available.
- ContinuousSummary
Character; one of
"mean"or"median".- ContinuousScaling
Character; one of
"zscore","none", or"minmax".- Fill
Logical; if TRUE, add transparent polygon fills in the static ggplot version and filled polygons in the interactive version.
- FillAlpha
Numeric transparency for fills.
- Facet
Logical; if TRUE and
GroupVariableis supplied, facet by group instead of overlaying all groups on one spider chart. Ignored wheninteractive = TRUE.- VariableOrder
Character; one of
"input","discrimination","hierarchical","greedy", or"category_discrimination".- VariableCategories
Optional character vector of categories for
Variables. Must be the same length asVariableswhen supplied.- BinaryPositiveValue
Optional positive value to use for non-factor binary variables. Defaults to
1. For factor variables, the second factor level is used.- Palette
Optional character name of an
hcl.colors()palette. WhenNULL(the default), the SciDataReportR palette is used. Passing a name such as"Dark 3"still works exactly as before.- LineSize
Numeric line width for the static ggplot version.
- PointSize
Numeric point size for the static ggplot version.
- ShowPoints
Logical; if TRUE, show points at each spoke in the static ggplot version.
- LegendTitle
Optional legend title. Defaults to
GroupVariable.- PlotTitle
Optional plot title.
- Subtitle
Optional plot subtitle.
- Caption
Optional plot caption.
- AxisLabelSize
Numeric axis text size for spoke labels in the static ggplot version.
- AxisTextSize
Numeric text size for radial axis labels in the static ggplot version.
- StripTextSize
Numeric facet strip text size in the static ggplot version.
- WrapLabels
Logical; if TRUE, wrap long spoke labels.
- LabelWrapWidth
Numeric wrap width passed to
stringr::str_wrap().- LabelRadiusMultiplier
Numeric multiplier controlling how far labels sit outside the spider in the static ggplot version.
- PlotMarginTop
Numeric top plot margin for the static ggplot version.
- PlotMarginRight
Numeric right plot margin for the static ggplot version.
- PlotMarginBottom
Numeric bottom plot margin for the static ggplot version.
- PlotMarginLeft
Numeric left plot margin for the static ggplot version.
- interactive
Logical; if TRUE, return an interactive plotly radar chart instead of a static ggplot. Default is
FALSE.- InteractiveHeight
Numeric height in pixels for the interactive widget.
- InteractiveWidth
Optional width passed to plotly layout. Defaults to NULL.
- InteractiveAxisMin
Optional numeric minimum for the interactive radial axis. If NULL, auto-detected from the summarized values.
- InteractiveAxisMax
Optional numeric maximum for the interactive radial axis. If NULL, auto-detected from the summarized values.
- tooltip_digits
Integer number of digits to show in interactive tooltips.
- Data
Deprecated (since 19.15.0). Use
datainstead.- Variables
Deprecated (since 19.15.0). Use
variablesinstead.- GroupVariable
Deprecated (since 19.15.0). Use
group_varinstead.- TooltipDigits
Deprecated (since 19.15.0). Use
tooltip_digitsinstead.- MakeInteractive
Deprecated (since 19.15.0). Use
interactiveinstead.
Examples
data(SampleData)
data(SampleVariableTypes)
Labelled <- RevalueData(SampleData, SampleVariableTypes)$RevaluedData
vars_biomarkers <- c(
"Ab_42", "p_tau", "tau", "GRO_alpha", "MMP10", "MMP7", "TRAIL_R3"
)
categories_biomarkers <- c(
"Neurodegeneration", "Neurodegeneration", "Neurodegeneration",
"Inflammation", "Inflammation", "Matrix remodeling", "TNF signaling"
)
# Input order preserves the supplied clinical/domain sequence.
PlotSpiderChart(
data = Labelled,
variables = vars_biomarkers,
group_var = "Diagnosis",
VariableOrder = "input"
)
# Discrimination puts the largest between-group differences next to each other.
PlotSpiderChart(
data = Labelled,
variables = vars_biomarkers,
group_var = "Diagnosis",
VariableOrder = "discrimination"
)
# Hierarchical order groups biomarkers with similar Diagnosis profiles.
PlotSpiderChart(
data = Labelled,
variables = vars_biomarkers,
group_var = "Diagnosis",
VariableOrder = "hierarchical"
)
# Greedy order places consecutive spokes with maximally different profiles.
PlotSpiderChart(
data = Labelled,
variables = vars_biomarkers,
group_var = "Diagnosis",
VariableOrder = "greedy"
)
# Category/discrimination order keeps domains together, then ranks the
# biomarkers within each domain by their between-group difference.
PlotSpiderChart(
data = Labelled,
variables = vars_biomarkers,
group_var = "Diagnosis",
VariableOrder = "category_discrimination",
VariableCategories = categories_biomarkers
)
# Interactive (plotly) version of the category-aware chart.
PlotSpiderChart(
data = Labelled,
variables = vars_biomarkers,
group_var = "Diagnosis",
VariableOrder = "category_discrimination",
VariableCategories = categories_biomarkers,
interactive = TRUE
)