生物信息分析

用VennDiagram画Venn图

2022-03-13  本文已影响0人  笺牒九州的怪咖

两图

venn.plot <- draw.pairwise.venn(  area1 = 80,  #区域1的数 
area2 = 30,   #区域2的数 
cross.area = 2,  #重叠的个数 
category = c("First", "Second"),#分类命名
fill = c("blue", "red"),#1 2 区域分别的填充颜色 
lty = "blank",  #1 2 区域的边框线类型 
cex = 2,        #1 2 区域内部数字的字体大小 
cat.cex = 2,    # 分类名称的字体大小 
cat.dist = 0.09,   #分类名称距离边的距离 实际调整 
cat.just = list(c(-1, -1), c(1, 1)),  #分类名称的位置  ,圈内或者圈外
ext.pos = 30,  #线的角度 默认是正上方12点位置 
ext.dist = -0.05,   #外部线的距离  跟根据圆圈的大小适当调整
ext.length = 0.85,  #外部线长度 
ext.line.lwd = 2,  #外部线的宽度 
ext.line.lty = "dashed" )  #外部线为虚线);
grid.draw(venn.plot)

三图

venn.plot <- draw.triple.venn(
area1 = 80,
area2 = 70,
area3 = 50,
n12 = 38,
n23 = 18,
n13 = 28,
n123 = 8,
category = c("First", "Second", "Third"),
fill = c("blue", "red", "green"),
lty = "blank",
cex = 2,
cat.cex = 2,
cat.col = c("blue", "red", "green"))
grid.draw(venn.plot)

四图

A <- sample(1:1000, 500, replace = FALSE);
B <- sample(1:1000, 600, replace = FALSE);
C <- sample(1:1000, 700, replace = FALSE);
D <- sample(1:1000, 800, replace = FALSE);
E <- sample(1:1000, 900, replace = FALSE);
venn.plot <- venn.diagram(#数据列表
x = list(A = A,B = B,C = C,D = D),
filename = "Venn_4set.png",    #保存文件名
col = "transparent",      #指定图形的圆周边缘颜色  transparent 透明          
fill = c("blue", "green", "yellow", "grey50"),  #填充颜色
alpha = 0.50,     #透明度
label.col = c("orange", "white", "grey50", "white","white", "white", "white", "white", "darkblue", "white","white", "white", "white", "darkgreen", "white"),
cex = 1.2,    #每个区域label名称的大小
cat.col = c("darkblue", "darkgreen", "orange", "grey50"),  #分类颜色
cat.cex = 1.2,      #每个分类名称大小
cat.dist = 0.07,   
cat.pos = 0,        #
cat.fontfamily = "serif",     #分类字体
rotation.degree = 0,        #旋转角度
margin = 0.2 )   
Venn_4set.png

五图

venn.plot <- venn.diagram( 
x = list(    A = A,    B = B,    C = C,    D = D,    E = E  ), 
filename = "Venn_5set.png", 
col = "black", 
fill = c("dodgerblue", "goldenrod1", "darkorange1", "seagreen3", "orchid3"), 
alpha = 0.50, 
cat.col = c("darkblue", "darkgreen", "orange", "grey50","purple"), 
cat.cex = 1.5, 
cat.fontface = "bold", 
margin = 0.05);
Venn_5set.png

画PDF格式

#将filename设置成NULL
#将画出来的图先保存到venn.plot中
venn.plot <- venn.diagram(
  x = list (
    A = 1:10,
    B = 6:25
  ),  
  cat.col=c("red","blue"),
  fill = c("red","blue"),
  filename = NULL
)

#将venn.plot通过grid.draw画到pdf文件中
pdf("venn.pdf")
grid.draw(venn.plot)
dev.off()
venn.pdf

导出Venn图的list

dat <- read.table('TEST.list', header = TRUE, sep = '\t',na.strings = "")  #有2列数据
venn.diagram(dat, filename = 'TEST.venn.png', imagetype = 'png', fill = c('red', 'blue'), alpha = 0.50, cat.col = rep('black', 1),col = 'grey', cex = 1.0,   fontfamily = 'serif',cat.cex = 1.0, cat.dist = 0.01,cat.just = list(c(-0.25, -0.25), c(1, 1)), cat.fontfamily = 'serif')
inter1 <- get.venn.partitions(dat)
for (i in 1:nrow(inter1)) inter1[i,'values'] <- paste(inter1[[i,'values']], collapse = ', ')
write.table(inter1[-c(3, 4)], 'TEST_venn_inter.txt', row.names = FALSE, sep = '\t', quote = FALSE)    #将Venn数据追加到第3和第4列
TEST.venn.png

TEST_venn_inter.txt:


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------I'm a line ! Thanks !---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

上一篇 下一篇

猜你喜欢

热点阅读