PanelPlot: Plot Micro-Panel (longitudinal) Data

Description Usage Arguments Value Examples

View source: R/PanelPlot.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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)

Example output

Warning messages:
1: In `[.data.table`(data, , ..group) :
  Both 'group' and '..group' exist in calling scope. Please remove the '..group' variable in calling scope for clarity.
2: In `[.data.table`(data, , ..colour) :
  Both 'colour' and '..colour' exist in calling scope. Please remove the '..colour' variable in calling scope for clarity.
3: In `[.data.table`(data, , ..group) :
  Both 'group' and '..group' exist in calling scope. Please remove the '..group' variable in calling scope for clarity.
4: In `[.data.table`(setDT(data), , ..colour, ) :
  Both 'colour' and '..colour' exist in calling scope. Please remove the '..colour' variable in calling scope for clarity.
`geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
Warning messages:
1: In `[.data.table`(data, , ..group) :
  Both 'group' and '..group' exist in calling scope. Please remove the '..group' variable in calling scope for clarity.
2: In `[.data.table`(data, , ..colour) :
  Both 'colour' and '..colour' exist in calling scope. Please remove the '..colour' variable in calling scope for clarity.
3: In `[.data.table`(data, , ..group) :
  Both 'group' and '..group' exist in calling scope. Please remove the '..group' variable in calling scope for clarity.
4: In `[.data.table`(setDT(data), , ..colour, ) :
  Both 'colour' and '..colour' exist in calling scope. Please remove the '..colour' variable in calling scope for clarity.
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
Warning messages:
1: In `[.data.table`(data, , ..group) :
  Both 'group' and '..group' exist in calling scope. Please remove the '..group' variable in calling scope for clarity.
2: In `[.data.table`(data, , ..colour) :
  Both 'colour' and '..colour' exist in calling scope. Please remove the '..colour' variable in calling scope for clarity.
3: In `[.data.table`(data, , ..group) :
  Both 'group' and '..group' exist in calling scope. Please remove the '..group' variable in calling scope for clarity.
4: In `[.data.table`(setDT(data), , ..colour, ) :
  Both 'colour' and '..colour' exist in calling scope. Please remove the '..colour' variable in calling scope for clarity.

CluMP documentation built on Nov. 27, 2020, 9:06 a.m.

Related to PanelPlot in CluMP...