This function generates an error-bar plot to visually compare different groups against a designated baseline group. It displays the central tendency (mean or median) as a bar and overlays error bars to represent the data's spread (e.g., standard deviation, MAD, or standard error). The plot can also include p-value and effect size labels (based on SSMD), presented either as symbols or numeric values, to highlight significant differences and the magnitude of effects.
cyt_errbp(
data,
group_col = NULL,
p_lab = FALSE,
es_lab = FALSE,
class_symbol = TRUE,
x_lab = "",
y_lab = "",
title = "",
log2 = FALSE,
output_file = NULL
)An error-bar plot (a ggplot object) is produced and optionally
saved as a PDF. If output_file is specified, the function returns
returns the ggplot object.
A data frame containing the data for each group. It should include at least one numeric column for the measurements and a column specifying the group membership.
Character. The name of the column in data that
specifies the group membership.
Logical. If TRUE, p-values are displayed on the plot.
Default is FALSE.
Logical. If TRUE, effect sizes (SSMD) are displayed on
the plot. Default is FALSE.
Logical. If TRUE, significance and effect size are
represented using symbolic notation (e.g., *, **, >, <<). If FALSE,
numeric values are used. Default is TRUE.
Character. Label for the x-axis. If not provided, defaults
to the name of the group_col or "Group" if group_col is NULL.
Character. Label for the y-axis. If not provided, defaults to "Value".
Character. Title of the plot. If not provided, a default title is generated based on the measured variables.
Logical. If TRUE, a log2 transformation (with a +1 offset)
is applied to all numeric columns before analysis. Default is FALSE.
Character. The file path to save the plot as a PDF.
If NULL, the plot is displayed but not saved. Default is NULL.
Xiaohua Douglas Zhang and Shubh Saraswat
The function performs the following steps:
Optionally applies a log2 transformation to numeric data.
Determines the baseline group (the first level of group_col).
Calculates summary statistics (sample size, mean, standard deviation) for each group and each numeric variable.
Performs t-tests to compare each group against the baseline for each numeric variable.
Computes effect sizes (SSMD) for each group compared to the baseline.
Generates a faceted error-bar plot, with one facet per numeric variable.
Optionally adds p-value and effect size labels to the plot.
Optionally saves the plot as a PDF.
data <- ExampleData1
cyt_errbp(data[,c("Group", "CCL.20.MIP.3A", "IL.10")], group_col = "Group",
p_lab = TRUE, es_lab = TRUE, class_symbol = TRUE, x_lab = "Cytokines",
y_lab = "Concentrations in log2 scale", log2 = TRUE)
Run the code above in your browser using DataLab