ggplot_spaghetti: Spaghetti Plots using 'ggplot2'

Description Usage Arguments Details Value Examples

View source: R/ggplot_spaghetti.R

Description

This function allows the user to create spaghetti plots for individuals with time varying covariates. You can also break this down into subgroups to analyze different trentds.

Usage

1
2
ggplot_spaghetti(y, id, time, alpha = 0.2, method = "loess", jit = 0,
  group = NULL, wrap = NULL, bw = FALSE, scales = NULL)

Arguments

y

This is the y-axis parameter to specify. Generally it is a continuous variable.

id

This is the id parameter that identifies the unique individuals or units.

time

This is the time vector and must be numeric.

alpha

Scalar value between [0,1] that specifies the transparencey of the lineplots.

method

Character value that specifies which type of method to use for fitting. Optional methods come from stat_smooth() funciton.

jit

Scalar value that specifies how much you want to jitter each individual observation. Useful if many of the values share the same y values at a time point.

group

Specifies a grouping variable to be used, and will plot it by color on one single plot.

wrap

Another possible grouping variable, but this will use 'facet_wrap()' to create separate plots for each grouping variable.

scales

Specify the scales paremeter for 'facet_wrap()' in ggplot2.

Details

Note that the data must be in long format.

Value

Plots a time series data by each individual/unit with group trends overlayed.

Examples

1
2
3
4
5
6
7
8
library(nlme)
data("Orthodont")
attach(Orthodont)
ortho_plot <- ggplot_spaghetti(distance, Subject, age, alpha = 0.3, group = Sex, method = "lm")+
xlab("Age (yrs.)")+
ylab("Distance")+
scale_color_discrete(name="Gender")
ortho_plot

williazo/ggplot.spaghetti documentation built on Feb. 7, 2018, 12:15 a.m.