#第一步
temp<-read.csv('mapp.csv',header=TRUE,row=1)
head(temp)
#第二步
temp$change <- as.factor(ifelse(temp$p < 0.01 & abs(temp$fc) > 1,ifelse(temp$fc > 1,'DOWN','UP'),'NOT'))#新增改列,利用ifelse函數(shù)添加基因的上下調(diào)情況徙融,color進行區(qū)分毡熏,然后使用geom_hline()和geom_vline()參數(shù)添加閾值線砖茸,
temp$sign <- ifelse(temp$p < 1.0e-60 & abs(temp$fc) > 3.9,rownames(temp),NA) #新增注冊列,利用ifelse函數(shù)添加重點顯著差異基因碉碉,然后使用geom_text參數(shù)添加到圖上柴钻,
library("ggplot2")
第三步
#p1 帶文字的
p1 <- ggplot(temp, aes(x =fc, y =-log10(q),color = change)) +
geom_point(size = 1.1,alpha=0.5) +
geom_vline(xintercept = c(-1, 1), lty = 4,color="black") +
geom_hline(yintercept = c(-2, 2), lty = 4,color="black") +
theme_bw()+
scale_color_manual(name = "", values = c("red", "blue", "black"), limits = c("UP", "DOWN", "NOT"))+#設(shè)置不同顏色
geom_text(aes(label = sign), size = 4,color="black") +#設(shè)置文字
labs(x = 'log2 Fold Change', y = '-log10 q-value')
p1
#p2 代標簽框的
library(ggrepel)
p2 <- ggplot(temp, aes(x =fc, y =-log10(q),color = change)) +
geom_point(size = 2,alpha=0.7) +
geom_vline(xintercept = c(-1, 1), lty = 4,color="black") +
geom_hline(yintercept = c(-2, 2), lty = 4,color="black") +
theme(panel.grid = element_blank(), panel.background = element_rect(color = 'black', fill = 'transparent'))+
scale_color_manual(name = "", values = c("red", "blue", "gray"), limits = c("UP", "DOWN", "NOT"))+
labs(x = 'log2 Fold Change', y = '-log10 q-value')+
geom_label_repel(aes(label=sign), fontface="bold",color="black", box.padding=unit(0.35, "lines"))#設(shè)置文本框
p2
image.png
4b876a8e21b060f6e6ca5d42bf6f1a8.jpg