【R>>volcan】任意genelist,标注到火山图
2021-05-25 本文已影响0人
高大石头
刷微信公众号时,翻到《火山图|给你geneList, 帮我标注到火山图上》的推文,刚好最近在做火山图,下面就来一起学习。如有疑问请翻阅原文,在最下面参考链接。
核心点:将不需要标注的用
NA
表示,left_join的妙用。
普通版火山图
rm(list = ls())
library(ggrepel) #避免标签重复
library(ggsci)
load("DEseq2_DEG.Rdata")
rt <- DEG
rt$change <- as.factor(ifelse(rt$padj<0.01 & abs(rt$log2FoldChange)>1,
ifelse(rt$log2FoldChange>1,"UP","DOWN"),"STABLE"))
rt$sign <- ifelse(rt$padj < 0.001 & abs(rt$log2FoldChange)>2.5,rownames(rt),NA)
head(rt)
ggplot(data = rt,
aes(x = log2FoldChange,
y = -log10(padj))) +
geom_point(alpha=1, size=3,
aes(color=change)) +
ylab("-log10(FDR)")+
xlab("log2(FoldChange)")+
scale_color_manual(values=c("#0073C2CC", "#868686CC","#CD534CCC"))+
geom_vline(xintercept=c(-1,1),lty=4,col="black",lwd=0.8) +
geom_hline(yintercept = -log10(0.05),lty=4,col="black",lwd=0.8)+
theme_light()+
theme(legend.position="none")
加上label
rm(list = ls())
library(ggrepel) #避免标签重复
library(ggsci)
load("DEseq2_DEG.Rdata")
rt <- DEG
rt$change <- as.factor(ifelse(rt$padj<0.01 & abs(rt$log2FoldChange)>1,
ifelse(rt$log2FoldChange>1,"UP","DOWN"),"STABLE"))
rt$sign <- ifelse(rt$padj < 0.001 & abs(rt$log2FoldChange)>2.5,rownames(rt),NA)
head(rt)
ggplot(data = rt,
aes(x = log2FoldChange,
y = -log10(padj))) +
geom_point(alpha=1, size=3,
aes(color=change)) +
ylab("-log10(FDR)")+
xlab("log2(FoldChange)")+
scale_color_manual(values=c("#0073C2CC", "#868686CC","#CD534CCC"))+
geom_vline(xintercept=c(-1,1),lty=4,col="black",lwd=0.8) +
geom_hline(yintercept = -log10(0.05),lty=4,col="black",lwd=0.8)+
theme_light()+
theme(legend.position="none")
指定genelist
genelist <- data.frame(id=c("MKI67","PCNA","BCL2","GPX4","TFRC"),genelist=c("MKI67","PCNA","BCL2","GPX4","TFRC"))
rt1 <- rt %>%
rownames_to_column("id") %>%
left_join(genelist,by="id")
ggplot(data = rt1,
aes(x = log2FoldChange,
y = -log10(padj))) +
geom_point(alpha=1, size=3,
aes(color=change)) +
ylab("-log10(FDR)")+
xlab("log2(FoldChange)")+
scale_color_lancet(alpha = 0.8)+
geom_vline(xintercept=c(-1,1),lty=4,col="black",lwd=0.8) +
geom_hline(yintercept = -log10(0.05),lty=4,col="black",lwd=0.8)+
theme_light()+
theme(legend.position="none")+
geom_label_repel(aes(label=genelist),
fontface="bold",
color="grey50",
box.padding = unit(0.35,"lines"),
point.padding = unit(0.5,"lines"),
segment.colour = "grey50",
size=3)
备注: 本内容仅限记录学习,如有侵权,请联系删除。
参考链接:
火山图|给你geneList,帮我标到火山图上