raw_plot {scdtb} | R Documentation |
Plot Raw Data with Optional Phase and Condition Annotations
Description
This function generates a plot of raw data from a specified data frame. It supports optional annotations based on phase and condition variables, and can facet the plot by participant. The plot is customizable with parameters for setting factor levels and labels for both phase and condition variables. It utilizes ggplot2 for plotting.
Usage
raw_plot(
.df,
.out,
.time,
.phase = NULL,
.cond = NULL,
.participant = NULL,
phase_levels = NULL,
phase_labels = NULL,
cond_levels = NULL,
cond_labels = NULL,
label_raise = 2
)
Arguments
.df |
A data frame containing the data to be plotted. Must contain columns specified by .time, .out, and optionally .phase, .cond, and .participant if used. |
.out |
The name of the column in .df that contains the outcome variable to be plotted on the y-axis. |
.time |
The name of the column in .df that contains the time variable to be plotted on the x-axis. |
.phase |
(Optional) The name of the column in .df that contains the phase variable used for annotating the plot with phase changes. If NULL, phase annotations are not added. |
.cond |
(Optional) The name of the column in .df that contains the condition variable. If not NULL, data points are colored based on condition. |
.participant |
(Optional) The name of the column in .df that contains participant identifiers. If not NULL, the plot is faceted by participant. |
phase_levels |
(Optional) A vector of values indicating the order of phase levels. This is used to set the factor levels of the phase variable. |
phase_labels |
(Optional) A vector of labels corresponding to the phase levels. These labels are used in annotations. |
cond_levels |
(Optional) A vector of values indicating the order of condition levels. This is used to set the factor levels of the condition variable. |
cond_labels |
(Optional) A vector of labels corresponding to the condition levels. These are used for the legend. |
label_raise |
A numeric value indicating how much to raise the phase labels on the y-axis. Defaults to 2. |
Value
A ggplot object representing the raw data plot with optional annotations for phase and condition, and faceting by participant if specified.
Examples
rp <- raw_plot(.df = efficacy_of_CBT, .out = "Anxious", .time = "time",
.phase = "phase", phase_levels = c(0, 1),
phase_labels = c("Exposure", "Exposure + CT"))