dynr.ggplot: The ggplot of the smoothed state estimates and the most...

View source: R/dynrPlot.R

dynr.ggplotR Documentation

The ggplot of the smoothed state estimates and the most likely regimes

Description

The ggplot of the smoothed state estimates and the most likely regimes

Usage

dynr.ggplot(res, dynrModel, style = 1, numSubjDemo = 2, idtoPlot = c(),
  names.state, names.observed, names.regime, shape.values, title, ylab,
  is.bw = FALSE, colorPalette = "Set2", fillPalette = "Set2",
  mancolorPalette, manfillPalette, ...)

## S3 method for class 'dynrCook'
autoplot(object, dynrModel, style = 1, numSubjDemo = 2,
  idtoPlot = c(), names.state, names.observed, names.regime, shape.values,
  title, ylab, is.bw = FALSE, colorPalette = "Set2", fillPalette = "Set2",
  mancolorPalette, manfillPalette, ...)

Arguments

res

The dynr object returned by dynr.cook().

dynrModel

The model object to plot.

style

The style of the plot. If style is 1 (default), user-selected smoothed state variables are plotted. If style is 2, user-selected observed-versus-predicted values are plotted.

numSubjDemo

The number of subjects to be randomly selected for plotting.

idtoPlot

Values of the ID variable to plot.

names.state

(optional) The names of the states to be plotted, which should be a subset of the state.names slot of the measurement slot of dynrModel.

names.observed

(optional) The names of the observed variables to be plotted, which should be a subset of the obs.names slot of the measurement slot of dynrModel.

names.regime

(optional) The names of the regimes to be plotted, which can be missing.

shape.values

(optional) A vector of values that correspond to the shapes of the points, which can be missing. See the R documentation on pch for details on possible shapes.

title

(optional) A title of the plot.

ylab

(optional) The label of the y axis.

is.bw

Is plot in black and white? The default is FALSE.

colorPalette

A color palette for lines and dots. It is a value passed to the palette argument of the ggplot2::scale_colour_brewer() function. These palettes are in the R package RColorBrewer. One can find them by attaching the package with library(RColorBrewer) and run display.brewer.all().

fillPalette

A color palette for blocks. It is a value passed to the palette argument of the ggplot2::scale_fill_brewer() function. These palettes are in the package RColorBrewer. One can find them by attaching the package with library(RColorBrewer) and run display.brewer.all().

mancolorPalette

(optional) A color palette for manually scaling the colors of lines and dots. It is a vector passed to the values argument of the ggplot2::scale_colour_manual function.

manfillPalette

(optional) A color palette for manually scaling the colors of filled blocks. It is a vector passed to the values argument of the ggplot2::scale_fill_manual function.

...

A list of elements that modify the existing ggplot theme. Consult the ggplot2::theme() function in the R package ggplot2 for more options.

object

The same as res. The dynr object returned by dynr.cook().

Details

This function outputs a ggplot layer that can be modified using functions in the package ggplot2. That is, one can add layers, scales, coords and facets with the "+" sign. In an example below, the ggplot2::ylim() function is used to modify the limits of the y axis of the graph. More details can be found on https://ggplot2.tidyverse.org/ and https://ggplot2.tidyverse.org/reference/.

The two functions dynr.ggplot() and autoplot() as identical aliases of one another. The autoplot() function is an S3 method from the package ggplot2 that allows many objects to be plotted and works like the base plot() function.

Value

ggplot object

ggplot object

Examples

# The following code is part of a demo example in dynr
## Not run: 
demo(RSLinearDiscreteYang, package='dynr')
p <- dynr.ggplot(yum, dynrModel = rsmod, style = 1,
 	names.regime = c("Deactivated", "Activated"),
 	title = "(B) Results from RS-AR model", numSubjDemo = 1,
 	shape.values = c(1),
 	text = element_text(size = 16),
 	is.bw = TRUE)
# One can modify the limits on the y axis by using '+'
p + ggplot2::ylim(-2, 4)

autoplot(yum, dynrModel = rsmod, style = 1,
	names.regime = c("Deactivated", "Activated"),
	title = "(B) Results from RS-AR model", numSubjDemo = 1,
	shape.values = c(1),
	text = element_text(size = 16),
	is.bw = TRUE)

## End(Not run)

dynr documentation built on May 29, 2024, 2:49 a.m.