Skip to contents

This function automatically selects and generates the most appropriate statistical visualization based on the data types of the selected variables. It supports both independent and repeated measurements designs, with various plot types including violin plots, scatter plots, bar charts, dot plots, and alluvial diagrams.

The function uses ggstatsplot package for statistical visualizations and ggalluvial for flow diagrams. Plot selection follows these rules:

  • Factor vs Continuous: Violin plots (ggbetweenstats/ggwithinstats)

  • Continuous vs Continuous: Scatter plots (ggscatterstats)

  • Factor vs Factor: Bar charts (ggbarstats) or Alluvial diagrams for repeated measures

  • Continuous vs Factor: Dot plots (ggdotplotstats)

Value

A results object containing plots and explanatory text

Details

The function intelligently selects plot types based on variable combinations:

Independent Measurements:

  • Factor + Continuous → Violin plot with statistical comparisons

  • Continuous + Continuous → Scatter plot with correlation analysis

  • Factor + Factor → Bar chart with contingency table analysis

  • Continuous + Factor → Cleveland dot plot

Repeated Measurements:

  • Factor + Continuous → Paired violin plot with within-subjects comparisons

  • Continuous + Continuous → Scatter plot (correlation analysis)

  • Factor + Factor → Alluvial diagram showing changes between time points

  • Continuous + Factor → Cleveland dot plot

Statistical tests are automatically selected based on the distribution parameter and variable types. All plots include appropriate statistical annotations.

Super classes

jmvcore::Analysis -> ClinicoPath::statsplot2Base -> statsplot2Class

Examples

# \donttest{
# Basic usage with factor and continuous variables
statsplot2(
  data = mtcars,
  dep = "mpg",
  group = "cyl",
  direction = "independent",
  distribution = "p"
)
#> Error in statsplot2(data = mtcars, dep = "mpg", group = "cyl", direction = "independent",     distribution = "p"): argument "grvar" is missing, with no default

# Repeated measures design with alluvial diagram
statsplot2(
  data = survey_data,
  dep = "condition_baseline", 
  group = "condition_followup",
  direction = "repeated",
  alluvsty = "t1"
)
#> Error in statsplot2(data = survey_data, dep = "condition_baseline", group = "condition_followup",     direction = "repeated", alluvsty = "t1"): argument "grvar" is missing, with no default
# }