1.安装包
install.packages('ggplot2')#已安装请绕过
install.packages('ggrepel')
library('ggplot2')
library('ggrepel')
2.导入数据(因人而异)
#生成一个向量
myfiles <- list.files(pattern = "*mFPKM.csv")
#选择导入向量中的第一个数据集
data <- read.csv(myfiles[1],header=T)#
3.加列
## 给数据集加一列sig:根据data中的pvalue和log2FoldChange给不同的标签
## #padj大于0.05或log2FoldChange小于1或大于-1的列定义为no
data$sig[(data$pvalue > 0.05|data$pvalue=="NA")|abs(data$log2FoldChange) < 1] <- "no"
data$sig[data$pvalue <= 0.05 & data$log2FoldChange >= 1] <- "up"
data$sig[data$pvalue <= 0.05 & data$log2FoldChange <= -1] <- "down"
4.画图
ggplot(data=data)+
geom_point(data=data,aes(x=log2FoldChange,y=-log10(pvalue),color=sig),alpha=0.8,size=3)+
#注意下标
labs(y=expression(log[10] (pvalue)))+
#注意下标
labs(x=expression(log[2](FoldChange)))+
theme(plot.title = element_text(hjust = 0.5,color="red",size=15),axis.title.x=element_text(size=15,family="serif"),axis.title.y=element_text(size=15,family="serif"))+# 水平方向位置
geom_hline(yintercept=1.3,linetype="dashed",size=1)+geom_vline(xintercept=c(-1,1),linetype=4,size=1)+#添加虚线,参数为dashed
#添加XY轴范围
xlim(-6,6)+ylim(0,30)+
scale_color_manual(values =c("#377EB8","grey","#E41A1C"))+
#scale_color_manual(values =c("green","blue", "red"))+
geom_text_repel(data=subset(data, data$pvalue <= 0.05 & abs(log2FoldChange) >= 1.3),aes(x=log2FoldChange,y=-log10(pvalue),label=Row.names),size=2.5)