Calculates summary statistics inline using ggplot2::stat_summary(), generating a line plot directly from raw data. Supports configurable central tendencies and dispersion metrics.

gg_lineplot(
  data,
  x,
  y,
  group = NULL,
  stat = c("mean", "median"),
  variability = c("ci", "sd", "se", "iqr", "none"),
  conf_level = 0.95
)

Arguments

data

(data.frame)
The raw data frame (e.g., ADaM dataset).

x

(tidy-select)
Column name for the x-axis timepoints (e.g., AVISIT).

y

(tidy-select)
Column name for the continuous variable to summarize (e.g., AVAL).

group

(tidy-select)
Optional column name for the grouping/treatment variable.

stat

(string)
Primary summary statistic: "mean" or "median". Default is "mean".

variability

(string)
Variability measure: "sd", "se", "ci", "iqr", or "none". Default is "ci".

conf_level

(numeric)
Confidence level for error bars when variability = "ci" (default: 0.95).

Value

A ggplot object of class crane_gg_line.

See also

annotate_lineplot_df() for related functionalities.

Examples

set.seed(123)
mock_adlb <- data.frame(
  ARM = rep(c("Treatment A", "Treatment B"), each = 30),
  AVISIT = rep(c(0, 4, 8), 20),
  AVAL = rnorm(60, mean = 10, sd = 2)
)

# 1. Default Plot: Mean with 95% Confidence Intervals
gg_lineplot(
  data = mock_adlb,
  x = AVISIT,
  y = AVAL,
  group = ARM
)
#>  We encourage to supply `x` as a factor, since it supports correct decimals
#>   formatting in the summary table.


# 2. Median with Interquartile Range (IQR)
gg_lineplot(
  data = mock_adlb,
  x = AVISIT,
  y = AVAL,
  group = ARM,
  stat = "median",
  variability = "iqr"
)
#>  We encourage to supply `x` as a factor, since it supports correct decimals
#>   formatting in the summary table.


# 3. Ungrouped data with Mean and Standard Deviation +
# Change legend position to top and add horizontal reference line
gg_lineplot(
  data = mock_adlb,
  x = AVISIT,
  y = AVAL,
  group = ARM,
  stat = "mean",
  variability = "sd"
) +
  ggplot2::theme(legend.position = "top") +
  ggplot2::geom_hline(
    yintercept = 30,
    linetype = "dashed",
    color = "gray50"
  )
#>  We encourage to supply `x` as a factor, since it supports correct decimals
#>   formatting in the summary table.