6: Publication-Quality Visualizations with ggplot2
Chapter 6: Publication-Quality Visualizations with ggplot2
Scientific publications in Nature, Science, and Cell require clean, high-DPI vector figures that adhere to Edward Tufte principles of data visualization. ggplot2 provides the Grammar of Graphics framework for building publication-grade figures.
1. Publication Volcano Plot
Rendering differential expression effect sizes against statistical significance with threshold cutoffs:
library(ggplot2)
p_volcano <- ggplot(volcano_df, aes(x = log2FC, y = -log10(padj), color = Significance)) +
geom_point(alpha = 0.65, size = 1.8) +
scale_color_manual(values = c("Downregulated" = "#0284C7", "Not Significant" = "#94A3B8", "Upregulated" = "#EF4444")) +
geom_vline(xintercept = c(-1.5, 1.5), linetype = "dashed", color = "#475569") +
geom_hline(yintercept = -log10(0.05), linetype = "dashed", color = "#475569") +
labs(
title = "RNA-Seq Differential Expression Volcano Plot",
x = expression(Log[2] ~ "Fold Change"),
y = expression(-Log[10] ~ "Adjusted P-Value (BH)")
) +
theme_minimal(base_size = 12)
ggsave("volcano_plot.pdf", plot = p_volcano, width = 7, height = 6, dpi = 300)2. Gene Expression Boxplot with Jittered Points
Visualizing individual patient data points overlaid on quartile boxplots:
p_box <- ggplot(expr_df, aes(x = Stage, y = TP53_TPM, fill = Stage)) +
geom_boxplot(alpha = 0.7, outlier.shape = NA, width = 0.5) +
geom_jitter(width = 0.15, alpha = 0.8, size = 2) +
scale_fill_brewer(palette = "Set2") +
labs(title = "TP53 Expression across Tumor Stages", y = "Normalized TPM", x = "Stage") +
theme_light(base_size = 12) +
theme(legend.position = "none")
ggsave("expression_boxplot.png", plot = p_box, width = 6.5, height = 5, dpi = 300)