使用VennDiagram包绘制韦恩图

使用VennDiagram包绘制韦恩图


加载所需R包

library(VennDiagram)
# 设置工作路径
setwd("/Users/Davey/Desktop/VennDiagram/")
# 清除当前环境中的变量
rm(list=ls())
# 读取测试数据
data = read.table("each_species_orthogroups.txt",header = T,sep="\t")
head(data)
         AT  Scaffold       VIT     Potri    LOC_Os        NC        Gb    Mapoly     Phpat       Smo   Sphfalx       kfl
1 OG0000000 OG0000000 OG0000000 OG0000000 OG0000000 OG0000000 OG0000000 OG0000000 OG0000000 OG0000000 OG0000000 OG0000000
2 OG0000001 OG0000001 OG0000001 OG0000001 OG0000001 OG0000001 OG0000001 OG0000001 OG0000001 OG0000001 OG0000001 OG0000001
3 OG0000002 OG0000002 OG0000002 OG0000002 OG0000002 OG0000002 OG0000002 OG0000002 OG0000002 OG0000002 OG0000002 OG0000002
4 OG0000003 OG0000003 OG0000003 OG0000003 OG0000003 OG0000003 OG0000003 OG0000003 OG0000003 OG0000003 OG0000003 OG0000004
5 OG0000004 OG0000004 OG0000004 OG0000004 OG0000004 OG0000004 OG0000004 OG0000004 OG0000004 OG0000004 OG0000004 OG0000005
6 OG0000005 OG0000005 OG0000005 OG0000005 OG0000005 OG0000005 OG0000005 OG0000005 OG0000005 OG0000005 OG0000005 OG0000006
        Cre     Vocar
1 OG0000000 OG0000000
2 OG0000001 OG0000001
3 OG0000002 OG0000002
4 OG0000004 OG0000005
5 OG0000005 OG0000006
6 OG0000006 OG0000008

绘制一维韦恩图

# 读入数据为list类型,默认图片保存为tiff格式
venn.plot <- venn.diagram(
  x = list(AT=data$AT),
  filename = "1single_Venn.tiff",
  col = "black", #边框颜色
  lwd = 5, #边框线宽度
  fontface = "bold", #标签字体
  fill = "grey", #填充色
  alpha = 0.7, #透明度
  cex = 4, #标签字体大小
  cat.cex = 3, #类名字体大小
  cat.fontface = "bold", #类名字体
  margin = 0.04 #边际距离
)
使用VennDiagram包绘制韦恩图_第1张图片
image.png

绘制二维韦恩图

# imagetype参数设定图片保存类型为png
venn.plot <- venn.diagram(
  x = list(
    AT = data$AT,
    Smo = data$Smo
  ),
  filename = "2double_Venn.png", imagetype = "png",
  lwd = 3,
  fill = c("cornflowerblue", "darkorchid1"),
  alpha = 0.6,
  label.col = "white",
  cex = 1.5,
  fontfamily = "serif",
  fontface = "bold",
  cat.col = c("cornflowerblue", "darkorchid1"),
  cat.cex = 2,
  cat.fontfamily = "serif",
  cat.fontface = "bold",
  margin = 0.05,
  cat.dist = c(0.03, 0.03),
  cat.pos = c(-20, 20)
)
使用VennDiagram包绘制韦恩图_第2张图片
2double_Venn.png

绘制三维韦恩图

venn.plot <- venn.diagram(
  x = list(
    AT = data$AT,
    VIT = data$VIT,
    Potri = data$Potri
  ),
  filename = "3triple_Venn.tiff",
  col = "transparent",
  fill = c("red", "blue", "green"),
  alpha = 0.5,
  label.col = c("darkred", "white", "darkblue", "white",
                "white", "white", "darkgreen"),
  cex = 2.5,
  fontfamily = "serif",
  fontface = "bold",
  cat.default.pos = "text",
  cat.col = c("darkred", "darkblue", "darkgreen"),
  cat.cex = 2.5,
  cat.fontfamily = "serif",
  cat.dist = c(0.06, 0.06, 0.03),
  cat.pos = 0
)
使用VennDiagram包绘制韦恩图_第3张图片
image.png

绘制四维韦恩图

venn.plot <- venn.diagram(
  x = list(
    AT = data$AT,
    Os = data$LOC_Os,
    Scaffold = data$Scaffold,
    Phpat = data$Phpat
  ),
  filename = "4quadruple_Venn.tiff",
  col = "black",
  lty = "dotted", #边框线型改为"dotted"虚线
  lwd = 3, # 边框线的宽度
  fill = c("cornflowerblue", "green", "yellow", "darkorchid1"),
  alpha = 0.50,
  label.col = c("orange", "white", "darkorchid4", "white", "white", "white",
                "white", "white", "darkblue", "white",
                "white", "white", "white", "darkgreen", "white"),
  cex = 2.0,
  fontfamily = "serif",
  fontface = "bold",
  cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"),
  cat.cex = 1.8,
  cat.fontface = "bold",
  cat.fontfamily = "serif"
)
使用VennDiagram包绘制韦恩图_第4张图片
image.png

绘制五维韦恩图

venn.plot <- venn.diagram(
  list(AT=data$AT,VIT=data$VIT,Os=data$LOC_Os,NC=data$NC,Scaffold=data$Scaffold),
  filename = "out5venn.tiff",
  lty = "dotted",
  lwd = 2,
  col = "black",  #"transparent",
  fill = c("dodgerblue", "goldenrod1", "darkorange1", "seagreen3", "orchid3"),
  alpha = 0.60,
  cat.col = c("dodgerblue", "goldenrod1", "darkorange1", "seagreen3", "orchid3"),
  cat.cex = 0.8,
  cat.fontface = "bold",
  margin = 0.07,
  cex = 0.8
)
使用VennDiagram包绘制韦恩图_第5张图片
image.png
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.3

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/zh_CN.UTF-8/zh_CN.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] VennDiagram_1.6.20  futile.logger_1.4.3 circlize_0.4.4     

loaded via a namespace (and not attached):
[1] colorspace_1.3-2     compiler_3.5.1       formatR_1.5          tools_3.5.1          GlobalOptions_0.1.0 
[6] lambda.r_1.2.3       futile.options_1.0.1 shape_1.4.4 

你可能感兴趣的:(使用VennDiagram包绘制韦恩图)