-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_plot_volcano.R
More file actions
54 lines (43 loc) · 1.48 KB
/
Copy path04_plot_volcano.R
File metadata and controls
54 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
###############################
# 04_plot_volcano.R
# Volcano plot
###############################
source("R/00_config.R")
suppressPackageStartupMessages({
library(ggplot2)
library(ggrepel)
})
result <- read.csv(file.path(table_dir, paste0(comparison_name, "_all_genes.csv")))
result$state <- "Not statistically significant"
result$state[
result$padj < padj_cutoff & result$log2FoldChange > lfc_cutoff
] <- paste0("Higher in ", target_group)
result$state[
result$padj < padj_cutoff & result$log2FoldChange < -lfc_cutoff
] <- paste0("Higher in ", reference_group)
label_genes <- result$gene[
result$padj < 0.01 &
abs(result$log2FoldChange) > lfc_cutoff
]
result$point_label <- ifelse(result$gene %in% label_genes, result$gene, "")
p <- ggplot(result, aes(x = log2FoldChange, y = -log10(padj))) +
geom_point(aes(color = state), size = 1.8, alpha = 0.8) +
geom_text_repel(aes(label = point_label), max.overlaps = 25, size = 3) +
geom_vline(xintercept = c(-lfc_cutoff, lfc_cutoff), linetype = "dashed") +
geom_hline(yintercept = -log10(padj_cutoff), linetype = "dashed") +
labs(
title = paste0(target_group, " minus ", reference_group),
x = "log2 fold change",
y = "-log10 adjusted p-value",
color = "Expression pattern"
) +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
ggsave(
filename = file.path(plot_dir, paste0("02_", comparison_name, "_volcano.pdf")),
plot = p,
width = 8,
height = 6,
dpi = plot_dpi
)
cat("Volcano plot saved\\n")