双阈值火山图
#######双阈值图
library(ggplot2)
logFC_t1 = 1
P.Value_t1 = 0.05
logFC_t2 = 2
P.Value_t2 = 0.01
dat = limma_voom_DEG
CENTER <- c("SLC4A1", "HBB", "HBA2", "HBG1", "HBG2","HBD","ALAS2","GYPA","AHSP")
library(dplyr)
k1 = with(dat,logFC > logFC_t2 & P.Value<P.Value_t2);table(k1)
k2 = with(dat,logFC < -logFC_t2 & P.Value<P.Value_t2);table(k2)
k3 = with(dat,logFC > logFC_t1 & P.Value < P.Value_t1 );table(k3)
k4 = with(dat,logFC < -logFC_t1 & P.Value <P.Value_t1 );table(k4)
设置不同颜色和大小
my_color = case_when(k1~"#EEA2AD", #设置点的颜色
k2~"#31A354",
k3~"#FFE4E1",
k4~"#BAE4B3",
TRUE~"#E8E8E8")
my_size = case_when(k1|k2~8, #调节点的大小
k3|k4~6,
TRUE~4)
p = ggplot(data = dat,
aes(x = logFC,
y = -log10(P.Value))) +
geom_point(alpha=0.5, size=my_size,
color=my_color) +
geom_vline(xintercept = c(-logFC_t1,logFC_t1,-logFC_t2,logFC_t2),lty= 4,lwd=0.8,alpha = c(0.5,0.5,1,1)) +
geom_hline(yintercept = c(-log10(P.Value_t1),-log10(P.Value_t2)),lty= 4,lwd=0.8,alpha = c(0.5,1)) + #调节线条的款式
theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
scale_x_continuous(limits = c(-4, 4), expand = c(0,0))###调节横坐标范围
p
加标签
dat <- as.data.frame(limma_voom_DEG)
symbol <- row.names(dat)
dat$symbol=symbol
for_label <- dat %>%
filter(symbol %in% c(CENTER))
p1 <- p +
geom_point(size = 6, shape = 1, data = for_label) +
ggrepel::geom_label_repel(
aes(label = symbol),
data = for_label,
color="black"
)
调节标签的大小
p1