安装R包
BiocManager::install("VennDiagram")
载入
library(VennDiagram)
查看数据,有三组,求这三组数据的交集
> head(gene_diff_select$gene_name)
[1] "SPARCL1" "PER1" "MT2A" "DUSP1" "MAOA"
[6] "KCTD12"
> head(DESeq2.df.gene$external_gene_name)
[1] "SPARCL1" "PER1" "MT2A" "DUSP1" "MAOA"
[6] "ZBTB16"
> head(yw.df.gene$Gene)
[1] "C7" "CCDC69" "DUSP1" "FKBP5" "GPX3" "KLF15"
#指定统计的分组列,并设置作图颜色、字体样式等
venn_list <- list(edegR = gene_diff_select$gene_name, DESeq2 = DESeq2.df.gene$external_gene_name, raw =yw.df.gene$Gene)
> venn.diagram(venn_list, filename = 'venn3.png', imagetype = 'png',
+ fill = c('red', 'blue', 'green'), alpha = 0.50, cat.col = rep('black', 3),
+ col = 'black', cex = 1.5, fontfamily = 'serif',
+ cat.cex = 1.5, cat.fontfamily = 'serif')
或者
venn.diagram(venn_list, filename = 'venn3.png', imagetype = 'png',
fill = c('red', 'blue', 'green'), alpha = 0.50,
cat.col = c('red', 'blue', 'green'), cat.cex = 1.5, cat.fontfamily = 'serif',
col = c('red', 'blue', 'green'), cex = 1.5, fontfamily = 'serif')
提取交集元素,VennDiagram包中的函数get.venn.partitions()可以实现这个功能
> overlap.gene <- get.venn.partitions(venn_list)
> View(overlap.gene)
> for (i in 1:nrow(overlap.gene)) overlap.gene[i,'values'] <- paste(overlap.gene[[i,'..values..']], collapse = ', ')
> View(overlap.gene)
> write.table(overlap.gene[-c(5, 6)], 'venn3_inter.txt', row.names = FALSE, sep = '\t', quote = FALSE)
网友评论