R语言中有很多程序包(package)可以做这个事情,包括limma,gplots,venneuler,还有今天我们下面要介绍的VennDiagram包。各个工具用起来差别不是很大,可
R语言中有很多程序包(package)可以做这个事情,包括limma, gplots, venneuler, 还有今天我们下面要介绍的VennDiagram包。各个工具用起来差别不是很大,可以根据个人喜好选择,不过其中limma包只能展示最多三个数据集的关系,后面三个包都可以展示超过三个数据集的维恩图。
1. 安装并加载包VennDiagram
> install.packages("VennDiagram")
> library(grid)
> library(VennDiagram)
2. 画维恩图的函数–venn.diagram()
VennDiagram包中画维恩图的函数是venn.diagram(). 下面我们来看一下venn.diagram()函数的使用及参数说明。
> venn.diagram(x, filename, height = 3000, width = 3000, resolution =
500, imagetype = "tiff", units = "px", compression =
"lzw", na = "stop", main = NULL, sub = NULL, main.pos
= c(0.5, 1.05), main.fOntface= "plain",
main.fOntfamily= "serif", main.col = "black",
main.cex = 1, main.just = c(0.5, 1), sub.pos = c(0.5,
1.05), sub.fOntface= "plain", sub.fOntfamily=
"serif", sub.col = "black", sub.cex = 1, sub.just =
c(0.5, 1), category.names = names(x), force.unique =
TRUE, print.mode = "raw", sigdigs = 3, direct.area =
FALSE, area.vector = 0, hyper.test = FALSE, total.population = NULL,
lower.tail = TRUE, ...)
部分参数说明:
x: a list of vectors, e.g: list(A=1:10, B=3:8, C=5:13)
filename: 设置图形输出文件名
resolution: 输出图形的清晰度,DPI数值
imagetype: 输出图形的格式,tiff, png, svg 等
alpha: 设置每个区块的透明度
main: 图形标题
main.fontface: 字体样式,比如斜体,粗体等
main.fontfamily: 字体,比如Time New Roman等
关于调解文字的,不仅可以针对标题调节,还有参数分别针对子标题,维恩图中每个部分(类别)的名字进行字体,大小,和字体样式的设置。
更多关于venn.diagram函数的参数说明可以查看其详细文档
venn.diagram官网: Make a Venn Diagram in VennDiagram: Generate High-Resolution Venn and Euler Plots (rdrr.io)
sample(x, size, replace=F) # 不放回抽样
二、venn基础图
1 两个圈
venn.diagram(
x = list(set1, set2),
category.names = c("Set 1" , "Set 2 "),
filename = 'venn.png',
output=TRUE
)
2 三个圈
venn.diagram(
x = list(set1, set2, set3),
category.names = c("Set 1" , "Set 2 " , "Set 3"),
filename = 'venn.png',
output=TRUE
)
3 四个圈
venn.diagram(
x = list(set1, set2, set3, set4),
category.names = c("Set 1" , "Set 2 " , "Set 3", "Set 4"),
filename = 'venn.png',
output=TRUE
)
4 五个圈
venn.diagram(
x = list(set1, set2, set3, set4, set5),
category.names = c("Set 1" , "Set 2 " , "Set 3", "Set 4", "Set 5"),
filename = 'venn.png',
output=TRUE
)
三、个性化参数调整
#调整参数进行图形优化
venn.plot
library(RColorBrewer)
color
四、保存
1 绘图待保存
library(RColorBrewer)
p = venn.diagram(
x = list(set1, set2, set3, set4, set5),
category.names = c("Set 1" , "Set 2 " , "Set 3", "Set 4", "Set 5"),
# filename = 'venn.png',
filename = NULL,
output=TRUE,
fill = brewer.pal(5, "Set2"),
col = brewer.pal(5, "Set3"),
fOntface= "bold",
cat.col = brewer.pal(5, "Set3"),
cat.fOntface= "bold"
)
2 保存为PDF
pdf("venn-pdf.pdf")
grid.draw(p)
dev.off()
3 保存为PNG
png("venn-png.png")
grid.draw(p)
dev.off()
更多参数:
col = NA # 边框设为无色
参考:https://www.r-graph-gallery.com/14-venn-diagramm.html
venn网页工具:http://bioinformatics.psb.ugent.be/webtools/Venn/
venn.diagram函数文档: https://www.rdocumentation.org/packages/VennDiagram/versions/1.6.20/topics/venn.diagram
The R Graph Gallery绘图教程:https://www.r-graph-gallery.com/index.html
如何使用R来绘制韦恩图(Venn Diagram) – 云+社区 – 腾讯云 (tencent.com)