差异基因火山图:ggplot2+ggrepel

ggrepel参考 火山图参考 调整图注参考1 图注参考2

install.packages("ggrepel")
library("ggplot2")
library("ggrepel")
resdata1 <- read.csv("trans_All_results.csv",header = TRUE)
resdata <- na.omit(resdata1)  ##此处是删除掉包含NA的行,这些行的结果不应纳入后续结果
threshold <- as.factor(ifelse(resdata$pvalue < 0.05 & abs(resdata$log2FoldChange) >= 1 ,ifelse(resdata$log2FoldChange >= 1 ,'Up','Down'),'Not'))
deg_img <- ggplot(resdata,aes(x=resdata$log2FoldChange,y=-log10(resdata$padj),colour=threshold)) + xlab("log2(Fold Change)")+ylab("-log10(qvalue)") + geom_point(size = 0.5,alpha=1) + ylim(0,82) + xlim(-18,18) + scale_color_manual(values=c("green","grey", "red"))

##添加阈值线
line_valcao <- deg_img+geom_hline(yintercept = 40,linetype="dotted")+geom_vline(xintercept=c(-1,1),linetype="dotted")

##使用ggrepel包给阈值范围以上的点添加标签
##注意此处是手动修改原始文件trans_All_result.csv,添加一列名称是label,内容是你选择显示的基因名称,只用写想显示的,不想显示的不用写,留空。
#threshold$label[1:20] <- resdata$X[1:20]
#threshold$label[21:length(resdata$X)] <- ""

valcano <- line_valcao+geom_text_repel(aes(label=resdata$label),point.padding = unit(0.25,"lines"),arrow = arrow(length=unit(0.01,"npc")),nudge_y = 0.1)+theme_classic(base_size = 14)
print(valcano)

trans_All_result.csv数据格式如图 image.png 最终的火山图结果如图所示。 image.png

回到页面顶部