One thin line per subject with an optional bold group mean overlaid — the standard way to show within-subject change without hiding spread.

geom_spaghetti(
  mapping = NULL,
  data = NULL,
  mean_line = TRUE,
  alpha = NULL,
  linewidth = NULL
)

Arguments

mapping, data

Standard layer overrides. Map time to x, the measurement to y, and the subject to group.

mean_line

Overlay the group mean trajectory.

alpha

Opacity of the individual lines.

linewidth

Width of the individual lines.

Value

A Layer to add with +.

Examples

set.seed(1)
d <- data.frame(
  week = rep(0:4, 8), id = rep(1:8, each = 5),
  score = as.vector(sapply(1:8, function(i) 50 + i + (0:4) * 2 + rnorm(5, 0, 3)))
)
ggnext(d, aes(week, score, group = id)) + geom_spaghetti()
#> <ggnext plot>
#>   data:  40 x 3
#>   aes:   x = week, y = score, group = id
#>   layers: 1 
#>   coord: cartesian
#>   mode:  static