Learn R Programming

jarbes (version 2.5.0)

plot_data: Plot Data Function

Description

This function plots the treatment effect (TE) against specified covariates or creates a forest plot of treatment effects, arranging up to four plots in a grid.

Usage

plot_data(
  data,
  formula = ~1,
  group = NULL,
  group.colors = NULL,
  study.label = NULL,
  x.lab = NULL,
  y.lab = "TE",
  title.plot = NULL,
  errbar.width = 0.25,
  label.size = 6,
  forest.color = "blue",
  forest.shape = 19,
  forest.size = 3,
  forest.group = NULL,
  forest.group.colors = NULL,
  xlim = NULL,
  ylim = NULL
)

Value

A `ggplot` object for a single plot or a `gridExtra` grob when multiple covariate plots are arranged in a grid.

Arguments

data

A data frame with columns `TE`, `seTE`, and the covariates.

formula

A one-sided formula (e.g., `~ x1 + x2`) for the x-axis variables. If not provided or set to `~1`, a forest plot is generated.

group

A character string specifying the name of the column in `data` to use for grouping the points (e.g., by color/fill) in covariate plots. Defaults to `NULL`. This parameter is ignored for forest plots.

group.colors

A character vector specifying colors for the groups when `group` is used in covariate plots. Can be a named vector where names match the levels of the grouping variable. Defaults to `NULL`, which uses ggplot2's default discrete colors.

study.label

A character string specifying the name of the column in `data` that contains the study labels for the forest plot. If `NULL`, default labels ("Study 1", "Study 2", etc.) are created.

x.lab

A character vector for x-axis labels. Defaults to variable names.

y.lab

Text for the y-axis label. Defaults to "TE" or "Study" for forest plots.

title.plot

Text for the plot title. Defaults to `NULL`.

errbar.width

The width of the error bars for covariate plots. Defaults to `0.25`.

label.size

A numeric value for the font size of the study labels in the forest plot. Defaults to `6`.

forest.color

The color of the points and error bars in a classic (ungrouped) forest plot. Defaults to `"blue"`.

forest.shape

The shape of the points in the forest plot. Defaults to `19` (filled circle).

forest.size

The size of the points in the forest plot. Defaults to `3`.

forest.group

A character string specifying the name of a column in `data` used to group and color studies in the forest plot (`formula = ~1`). If `NULL`, a single-color forest plot is produced.

forest.group.colors

A character vector specifying colors for forest plot groups when `forest.group` is used. Can be a named vector matching group levels. If `NULL`, colors are assigned automatically: two groups use blue and red; three or more groups use a Brewer palette.

xlim

A numeric vector of length 2 specifying x-axis limits.

ylim

A numeric vector of length 2 specifying y-axis limits.

Details

In forest plot mode (`formula = ~1`), studies can optionally be colored by a grouping variable using `forest.group`.