韦恩图脚本

2021-04-22  本文已影响0人  萍智医信

例子一

#NPC_vs_control添加logFC,change列,标记上下游基因
library(readxl)
NPC_vs_control <- read_excel("E://应用软件//RStudio+ R//R Project//Frist//NPC vs control.xlsx")
View(NPC_vs_control)
a<-NPC_vs_control
a$logFC<-log2(a$`FC (NPC vs control)`)

logFC_t=1
P.Value_t = 0.05
k1 = (a$`p-value` < P.Value_t)&(a$logFC < -logFC_t)
k2 = (a$`p-value` < P.Value_t)&(a$logFC > logFC_t)
a$change = ifelse(k1,"down",ifelse(k2,"up","stable"))
write.csv(a,file = "NPC vs control(alter).csv")

#M1_VS_M0添加logFC,change列,标记上下游基因
library(readxl)
M1_VS_M0 <- read_excel("E://应用软件//RStudio+ R//R Project//Frist//M1 VS M0.xlsx")
View(M1_VS_M0)
b<-M1_VS_M0
b$logFC<-log2(b$`FC (M1 vs M0)`)

logFC_t=1
P.Value_t = 0.05
k3 = (b$`P-VALUE`< P.Value_t)&(b$logFC < -logFC_t)
k4 = (b$`P-VALUE`< P.Value_t)&(b$logFC > logFC_t)
b$change = ifelse(k3,"down",ifelse(k4,"up","stable"))
write.csv(b,file = "M1_VS_M0(alter).csv")

#Pos_vs_Neg添加logFC,change列,标记上下游基因
library(readxl)
Pos_vs_Neg <- read_excel("E://应用软件//RStudio+ R//R Project//Frist//Pos vs Neg.xlsx")
View(Pos_vs_Neg)
c<-Pos_vs_Neg
c$logFC<-log2(c$`FC (Pos vs Neg)`)

logFC_t=1
P.Value_t = 0.05
k5 = (c$`P-VALUE` < P.Value_t)&(c$logFC < -logFC_t)
k6 = (c$`P-VALUE` < P.Value_t)&(c$logFC > logFC_t)
c$change = ifelse(k5,"down",ifelse(k6,"up","stable"))
write.csv(c,file = "Pos_vs_Neg(alter).csv")

#a(NPC_vs_control)提取上下游基因
aup<-a[which(a$change=="up"),]
adown<-a[which(a$change=="down"),]
write.csv(aup,file = "aup(NPC_vs_control).csv")
write.csv(adown,file = "adown(NPC_vs_control).csv")

#b(M1_VS_M0)提取上下游基因
bup<-b[which(b$change=="up"),]
bdown<-b[which(b$change=="down"),]
write.csv(bup,file = "bup(M1_VS_M0).csv")
write.csv(bdown,file = "bdown(M1_VS_M0).csv")

#c(Pos_vs_Neg)提取上下游基因
cup<-c[which(c$change=="up"),]
cdown<-c[which(c$change=="down"),]
write.csv(cup,file = "cup(Pos_vs_Neg).csv")
write.csv(cdown,file = "cdown(Pos_vs_Neg).csv")

#d(GEO NPC vs Normal)提取上下游基因
library(readr)
GEO_NPC_vs_Normal <- read_csv("E://应用软件//RStudio+ R//R Project//Frist//GEO NPC vs Normal.csv")
View(GEO_NPC_vs_Normal)
d<-GEO_NPC_vs_Normal
dup<-d[which(d$change=="up"),]
ddown<-d[which(d$change=="down"),]
write.csv(dup,file = "dup(GEO NPC vs Normal).csv")
write.csv(ddown,file = "ddown(GEO NPC vs Normal).csv")

#绘制二维韦恩图
library(VennDiagram)
venn.diagram(list(NvsC=aup1_NPC_vs_control_$`genge name`,GEO=dup$`genge name`),
             resolution = 300, imagetype = "tiff", alpha = 0.50,
             fill=c("red","blue",), cat.fontface=4,fontfamily=3,
             main="NPCvsControl上调基因验证",#设置标题名称
             cex = 1.5,#设置数字大小
             cat.cex = 1.5, #设置标签大小
             cat.fontfamily = 'serif',
             main.cex = 2, main.fontface = 2, main.fontfamily = 3,
             filename = "VennDiagram1.tif")

#四维韦恩图(up)
library(VennDiagram)
venn.diagram(list(NvsC=aup1_NPC_vs_control_$`genge name`,
                  GEO=dup$`genge name`,
                  M1vsM0=bup$`genge name`,
                  PvsN=cup$`gene name`
),
resolution = 300, imagetype = "tiff", alpha = 0.50,
fill=c("red","blue","green","yellow"), cat.fontface=4,fontfamily=3,
main="UP",#设置标题名称
cex = 1.5,#设置数字大小
cat.cex = 1.5, #设置标签大小
cat.fontfamily = 'serif',
main.cex = 2, main.fontface = 2, main.fontfamily = 3,
filename = "UP.tif")

#四维韦恩图(down)
venn.diagram(list(NvsC=adown1_NPC_vs_control_$`genge name`,
                  GEO=ddown$`genge name`,
                  M1vsM0=bdown$`genge name`,
                  PvsN=cdown$`gene name`
),
resolution = 300, imagetype = "tiff", alpha = 0.50,
fill=c("red","blue","green","yellow"), cat.fontface=4,fontfamily=3,
main="DOWN",#设置标题名称
cex = 1.5,#设置数字大小
cat.cex = 1.5, #设置标签大小
cat.fontfamily = 'serif',
main.cex = 2, main.fontface = 2, main.fontfamily = 3,
filename = "DOWN.tif")

例子二

#读取数据
rt1=read.table("tcgaDiffRBPexp.txt",sep="\t",check.names=F,header=T)
rt2=read.table("node.txt",sep="\t",check.names=F,header=T)
rt3=read.table("geoMatrix.txt",sep="\t",check.names=F,header=T)

#三维韦恩图
p<-venn.diagram(list(TCGA_HNSCC=rt1$Gene,
                  PPI=rt2$Gene,
                  GEO_HNSCC=rt3$Gene
              ),
resolution = 300, imagetype = "png", alpha = 0.50,#透明度
fill=c("red","blue","green"), fontfamily=3,#cat.fontface=4,
main="common RBPs",#设置标题名称
cex = 3.5,#设置标签数字大小
#fontface = "bold", #标签字体
cat.cex = 2.5, #设置种类标签大小
cat.fontface = "bold", #类标签字体
margin = 0.15, #边际距离
cat.fontfamily = 'serif',
main.cex = 3, main.fontface = 2, main.fontfamily = 3,#标题大小字体
filename = "common RBPs.png")

vennDiagram虽然是我画Vene图首选,但是画两个以上就不会按数据比例画圆圈,而是一样大的圆。但是vennerable可以,唯一不足的是颜色不能设置
原文链接:https://blog.csdn.net/sbt8814564153/article/details/105678939

# BiocManager::install("RBGL","reshape")
install.packages("Vennerable", repos="http://R-Forge.R-project.org")
library(vennerable)
data<-Venn(list("186"=paper,"100"=my, "7"= vgene))    #使用Venn函数处理数据,完成了集合的命名并存入
data(变量名可以随便起)
plot(data,doWeight=T) # doWeight即按比例权重画圈
vennerable.png
上一篇下一篇

猜你喜欢

热点阅读