Skip to content

Commit 5ffc734

Browse files
EkinEkin
authored andcommitted
fixing ma plot
1 parent d619251 commit 5ffc734

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

results/figures/ma_plot.png

348 KB
Loading

scripts/05_model_diagnostics.R

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,26 @@ dir.create("results/figures", recursive = TRUE, showWarnings = FALSE)
1515

1616
message("Generating diagnostic plots...")
1717

18-
# MA plot
18+
# MA plot using ggplot2
1919
res <- results(dds, contrast = c("condition", "positive", "negative"), alpha = 0.05)
20-
21-
png("results/figures/ma_plot.png", width = 7, height = 6, units = "in", res = 300)
22-
plotMA(res, ylim = c(-8, 8), main = "MA Plot: Mean Expression vs Log2 Fold Change")
20+
res_ma <- as.data.frame(res)
21+
res_ma$baseMean_log <- log10(res_ma$baseMean + 1)
22+
res_ma$sig <- ifelse(!is.na(res_ma$padj) & res_ma$padj < 0.05, "Significant", "NS")
23+
24+
png("results/figures/ma_plot.png", width = 7, height = 6, units = "in", res = 300, bg = "white")
25+
print(ggplot(res_ma, aes(x = baseMean_log, y = log2FoldChange, color = sig)) +
26+
geom_point(alpha = 0.4, size = 1) +
27+
scale_color_manual(values = c("NS" = "grey50", "Significant" = "#e74c3c")) +
28+
geom_hline(yintercept = 0, linetype = "dashed") +
29+
labs(
30+
title = "MA Plot: Mean Expression vs Log2 Fold Change",
31+
x = "Mean Expression (log10)",
32+
y = "Log2 Fold Change",
33+
color = ""
34+
) +
35+
ylim(-8, 8) +
36+
theme_classic(base_size = 12) +
37+
theme(plot.title = element_text(face = "bold", hjust = 0.5)))
2338
dev.off()
2439

2540
# Dispersion estimates

0 commit comments

Comments
 (0)