PanelPlot {CluMP}R Documentation

Plot Micro-Panel (longitudinal) Data

Description

This function plots micro-panel (longitudinal) data from stored data.frame or randomly generated panel data from GeneratePanel function.

Usage

PanelPlot(
  data,
  formula = Y ~ Time,
  group = "ID",
  colour = NA,
  mean_traj_all = FALSE,
  mean_traj_group = FALSE,
  show_legend = TRUE,
  title = NULL,
  x_title = NULL,
  y_title = NULL
)

Arguments

data

A data frame containing the variables named in formula and group arguments.

formula

A two-sided formula object, with a numeric, clustering variable (Y) on the left of a ~ separator and the time (numeric) variable on the right. Time is measured from the start of the follow-up period (baseline).

group

A grouping factor variable (vector), i.e. single identifier for each (trajectory).

colour

Character, which is a variable's name in data. The trajectories are distinguished by colour according to this variable.

mean_traj_all

Logical scalar. It indicates whether to show mean overall trajectory. Default is FALSE.

mean_traj_group

Logical scalar. It indicates whether to show mean trajectory by group. Default is FALSE.

show_legend

Logical scalar. It indicates whether to show cluster legend. Default is TRUE.

title

String. Is an optional title for a plot. Otherwise no title will used.

x_title

String. Is an optional title for x axis. Otherwise variable name after ~ in formula will used.

y_title

String. Is an optional title for y axis. Otherwise variable name before ~ in formula will used.

Value

Returns plot using package ggplot2.

Examples

set.seed(123)
dataMale <- GeneratePanel(n = 50, Param = ParamLinear, NbVisit = 10)
dataMale$Gender <- "M"
dataFemale <- GeneratePanel(n = 50, Param = ParamLinear, NbVisit = 10)
dataFemale$ID <- dataFemale$ID + 50
dataFemale$Gender <- "F"
data <- rbind(dataMale, dataFemale)

PanelPlot(data = data, formula = Y ~ Time, group = "ID", colour = "Gender")
PanelPlot(data = data, formula = Y ~ Time, group = "ID", colour = "Gender", mean_traj_all = TRUE)
PanelPlot(data = data, formula = Y ~ Time, group = "ID", colour = "Gender", mean_traj_group = TRUE)

[Package CluMP version 0.8.1 Index]