Skip to contents

'Create ridgeline plots to visualize and compare distributions of a continuous variable across different categorical groups. Useful for showing distribution shapes, overlaps, and differences between groups.'

Usage

jjridgestats(
  data,
  dep,
  group,
  plotStyle = "density",
  scaling = 1,
  bandwidth = 1,
  binwidth = 1,
  fill = TRUE,
  colorscheme = "viridis",
  customColor = "#4682B4",
  themeChoice = "minimal",
  legendPosition = "none",
  mytitle = "",
  xtitle = "",
  ytitle = ""
)

Arguments

data

The data as a data frame.

dep

The continuous numeric variable to display as ridgeline distributions. This variable will be plotted along the x-axis, with separate density curves or histograms for each group level.

group

The categorical grouping variable that defines the different ridges. Each level of this variable will create a separate ridge (density curve or histogram) in the plot, arranged vertically.

plotStyle

Type of ridgeline plot to create. 'density' creates smooth density curves, 'histogram' creates histogram-style ridges with discrete bins, 'gradient' creates density ridges with color gradients based on x-values.

scaling

Controls the height scaling of the ridges. Values > 1 make ridges taller and may create overlapping ridges for dramatic effect. Values < 1 make ridges shorter with more separation between groups.

bandwidth

Controls the smoothness of density ridges. Larger values create smoother, wider curves. Smaller values create more detailed, narrower curves that follow the data more closely. Only applies to density and gradient styles.

binwidth

Width of histogram bins when using histogram plot style. Smaller values create more detailed histograms with narrower bins. Larger values create smoother histograms with wider bins.

fill

Whether to fill the ridges with color. If TRUE, ridges are filled with colors based on the color scheme. If FALSE, only outlines are shown. Filled ridges are better for comparing distributions.

colorscheme

Color palette for filling ridges. Viridis, plasma, and magma are colorblind-friendly perceptually uniform scales. Blues uses a sequential blue palette. Custom allows specification of a custom color.

customColor

Custom fill color when colorscheme is set to 'custom'. Specify as a hex color code (e.g., '#4682B4' for steel blue) or standard color name (e.g., 'steelblue'). Only used when colorscheme = 'custom'.

themeChoice

Overall plot theme style. 'minimal' uses clean ridgeline-specific theme, 'classic' uses traditional ggplot2 theme with borders, 'dark' uses dark background theme suitable for presentations.

legendPosition

Position of color legend. 'none' hides legend (recommended for ridgeline plots since y-axis labels show groups), 'right' places legend on right side, 'bottom' places legend below plot.

mytitle

Main plot title. Leave empty for automatic title or specify custom title for the ridgeline plot (e.g., 'Distribution of Biomarker Levels by Disease Stage').

xtitle

X-axis label. Leave empty to use variable name or specify custom label for the continuous variable (e.g., 'Biomarker Expression (ng/mL)').

ytitle

Y-axis label. Leave empty to use grouping variable name or specify custom label for the grouping variable (e.g., 'Disease Stage').

Value

A results object containing:

results$todoa html
results$plotan image

Examples

# \donttest{
# Load test data
data(jjridgestats_test_data)
#> Warning: data set ‘jjridgestats_test_data’ not found

# Basic ridgeline plot
jjridgestats(
  data = jjridgestats_test_data,
  dep = "biomarker_expression",
  group = "disease_stage",
  plotStyle = "density"
)
#> Error: object 'jjridgestats_test_data' not found

# Customized ridgeline plot
jjridgestats(
  data = jjridgestats_test_data,
  dep = "response_score",
  group = "treatment_group",
  plotStyle = "gradient",
  scaling = 2.0,
  colorscheme = "viridis",
  fill = TRUE
)
#> Error: object 'jjridgestats_test_data' not found

# Histogram-style ridgeline
jjridgestats(
  data = jjridgestats_test_data,
  dep = "lab_value",
  group = "hospital_center",
  plotStyle = "histogram",
  binwidth = 5
)
#> Error: object 'jjridgestats_test_data' not found
# }