#第一步
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函数添加基因的上下调情况,color进行区分,然后使用geom_hline()和geom_vline()参数添加阈值线,
temp$sign <- ifelse(temp$p < 1.0e-60 & abs(temp$fc) > 3.9,rownames(temp),NA) #新增注册列,利用ifelse函数添加重点显着差异基因,然后使用geom_text参数添加到图上,
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"))+#设置不同颜色
geom_text(aes(label = sign), size = 4,color="black") +#设置文字
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"))#设置文本框
p2
image.png
4b876a8e21b060f6e6ca5d42bf6f1a8.jpg
网友评论