- 这些东西,换成是高中的我们来做,应该会笑吧,原来长大后的考验也不过如此;
- 其实就是把差异分析结果中的logFC(fold change,limma中给出的结果经由log2处理)和p.value拎出来 ,以log2FC为x轴,-log10(p.value)为y轴对数据进行展示而已;
- 理解,stable、up-regulated、down-regulated的界定,都是未成文的cutoff(|log2FC|>1,p.value<0.05或p.value<0.01)而已;
#####从limma中得到p.value,logFC等值;
dff<-topTable(fit2,number=nrow(fit2))
dff <- subset(dff, select=c("P.Value","logFC"))
dff$'log10_P.Value'= -log10(dff$P.Value)
dff$total=ifelse(dff$P.Val>0.05,'stable',
ifelse( dff$logFC >1,'up',
ifelse( dff$logFC < -1,'down','stable') )
)
dff$name=rownames(dff)
####火山图
library(ggpubr)
ggscatter(dff, x = "logFC", y = "log10_P.Value", color = "total",size = 0.75)
- 对数据处理部分就是把logFC和p.value的数值基于展示的要求处理;
- 基于logFC和p.value,用ifelse把p.val大于0.05归为stable,小于0.05的部分,用logFC划分(logFC>1为up,(logFC<1的范围中,logFC<-1为down,-1<logFC<1为stable))
-
ggscatter里面的参数,dff为数据,x选dff中的logFC那一列,y选dff中log_10p.value那一列,以dff中的total(把数据分成了up,down,stable三种)进行上色;size设置点的大小;
total=dff$total
library(ggplot2)
qplot(x=dff$logFC, y=-log10(dff$P.Value),color= total)+xlab("log2 fold change") + ylab("-log10 p-value")+theme_bw()+scale_colour_manual(values = c('up'="blue",'stable'='grey','down'='red'))
- qplot中,x和y直接指定用来画图的数据,color用来指定进行上色的数据,xlab和ylab为x轴和y轴添加名字,scale_colour_manual对上色的数据指定具体的颜色;
with(subset(dff, adj.P.Val<.05 ),plot(logFC, log10_P.Value,pch=20, col="red"))
with(subset(dff, abs(logFC)>1), points(logFC, log10_P.Value, pch=20, col="orange"))
with(subset(dff, adj.P.Val<.05 & abs(logFC)>1), points(logFC, log10_P.Value, pch=20, col="green"))
# Label points with the textxy function from the calibrate plot
library(calibrate)
TF_gene<-c('ONECUT2','RAPGEF5','SIX2','MYT1L','ASCL1','PROX1','INSM1','ZNF711','MYT1')
with(subset(dff, adj.P.Val<.05 & abs(logFC)>1), textxy(logFC, log10_P.Value, labs=dff$SYMBOL[dff$SYMBOL%in%TF_gene], cex=.8))
-
这里是一个实际的需求,将具体的基因名加到图中,但明显这个图不漂亮,之后琢磨了强大的ggplot2后再把代码更新一下;这里用的数据,我已经把ENSEMBL 转换成SYMBOL了,但代码粗糙,未作展示;
课程分享
生信技能树全球公益巡讲
(https://mp.weixin.qq.com/s/E9ykuIbc-2Ja9HOY0bn_6g)
B站公益74小时生信工程师教学视频合辑
(https://mp.weixin.qq.com/s/IyFK7l_WBAiUgqQi8O7Hxw)
招学徒:
(https://mp.weixin.qq.com/s/KgbilzXnFjbKKunuw7NVfw)
网友评论