Creates a high-quality bar plot to compare thermal metrics across experimental groups. The visualization includes bars representing the mean, customizable error bars (SD or SE), and overlaid individual data points to show biological variation.
viz_thermal_barplot(
data,
y_var,
x_var,
fill_var = NULL,
error_bar = "mean_sd",
add_points = TRUE,
point_size = 1.5,
point_alpha = 0.6,
palette = "npg"
)A ggplot object. Can be further customized with standard ggplot2 functions.
Data frame. The merged dataset (e.g., output from aggregate_replicates).
String. The name of the numeric column to plot (e.g., "Max_Temp", "Mean_Temp").
String. The name of the categorical column for the X-axis groupings (e.g., "Treatment", "Genotype").
String. The name of the variable used for fill colors. Default is NULL, which uses x_var.
String. The type of error bar to display. Options:
"mean_sd": Mean +/- Standard Deviation (shows spread of data).
"mean_se": Mean +/- Standard Error of the Mean (shows precision of the mean).
Logical. If TRUE (default), overlays individual data points using geom_jitter.
This is highly recommended for small sample sizes (n < 20) to maintain transparency.
Numeric. The size of the individual jitter points. Default is 1.5.
Numeric. The transparency of the jitter points (0 = transparent, 1 = opaque). Default is 0.6 to handle overlapping points.
String or Vector.
If a string: Pre-defined scientific palettes ("npg" for Nature Publishing Group, "jco" for Journal of Clinical Oncology).
If a character vector: A custom list of hex codes (e.g., c("#FF0000", "#0000FF")).
This function is designed to produce figures that are immediately suitable for scientific manuscripts. Key features include:
Automatic Statistics: Calculates Mean and SD/SE internally using stat_summary.
Smart Coloring: Supports scientific palettes ("npg", "jco"). If the number of groups exceeds the palette size, it automatically interpolates to generate distinct colors.
Layout: Uses theme_classic() and automatically expands the Y-axis limit
by 15% to ensure error bars and significance annotations fit comfortably.
df_bio <- data.frame(
Treatment = rep(c("ND", "HFD"), each = 5),
Mean = c(runif(5, 33, 35), runif(5, 34, 36))
)
# Boxplot with individual points
p <- viz_thermal_barplot(df_bio,y_var="Mean",x_var="Treatment",error_bar = "mean_se")
p
Run the code above in your browser using DataLab