3.5 Venn Diagram Venn图的绘制:三维和四维Venn图的绘制
Venn图是可以表示某个值在不同组中的交集和并集关系,因此可以是数值、字符串(即文字)类的相互重叠和不重叠部分的展示。
3.5.1 三维Venn图的绘制:
数据格式:
image.png
install.packages('VennDiagram')#安装包
library(VennDiagram)#导入包
sdv<-read.csv(file.choose())#读取数据
三维Venn图的绘制:
sdv.plot <- venn.diagram(
x = list( Pyloric.caeca=sdv$Pyloric.caeca, Midgut = sdv$Midgut, Hindgut = sdv$Hindgut),
filename = 'C:/Users/Mr.R/Documents/ReproduceImages/Reproduction1 Core gut microbial communities are maintained by beneficial interactions and strain/sdvVennDiagram.tiff',
col = "black", lwd = 1,
fill = c("cornflowerblue", "green", "yellow"),alpha = 0.20, cex = 0.6, fontfamily = "serif", fontface = "bold", cat.col = c("darkblue", "darkgreen", "orange"), cat.cex = 1.2,
cat.fontface = "bold",cat.fontfamily = "serif")
得到的结果为:
image.png
3.5.2 四维Venn图的绘制
1)数据格式为:
image.png
首先安装对应的包并加载
install.packages('VennDiagram')#安装包
library(VennDiagram)#导入包
读取数据
vn= read.table('C:/Users/Mr.R/Documents/ReproduceImages/Reproduction1 Core gut microbial communities are maintained by beneficial interactions and strain/venn.txt', header = T,sep="\t")
head(vn)#显示数值首6行
image.png
开始作图:
venn.plot <- venn.diagram(
x = list( High.marine.Protein= vn$High.marine.Protein, Medium.fat = vn$Medium.fat, High.fat = vn$High.fat, Low.marine.protein = vn$Low.marine.protein ),
filename = 'C:/Users/Mr.R/Documents/ReproduceImages/Reproduction1 Core gut microbial communities are maintained by beneficial interactions and strain/VennDiagram1.tiff',
col = "black", lty = "dotted",lwd = 1,
fill = c("cornflowerblue", "green", "yellow", "darkorchid1"),alpha = 0.20,
label.col = c("orange", "white", "darkorchid4", "white", "white", "white","white", "white", "darkblue", "white", "white", "white", "white", "darkgreen", "white"),
cex = 0.6, fontfamily = "serif", fontface = "bold",
cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"), cat.cex = 0.6,
cat.fontface = "bold",cat.fontfamily = "serif")
得到以下图形:
image.png
说明
:
x = list( High.marine.Protein= vn$High.marine.Protein, Medium.fat = vn$Medium.fat, High.fat = vn$High.fat, Low.marine.protein = vn$Low.marine.protein ),#形成list
filename = 'C:/Users/Mr.R/Documents/ReproduceImages/Reproduction1 Core gut microbial communities are maintained by beneficial interactions and strain/VennDiagram1.tiff', #输出位置和图片格式
col = "black", lty = "dotted", #边框线型为"dotted"可以得到虚线,如果不赋值会默认实现
lwd = 1, # 边框线的宽度
fill = c("cornflowerblue", "green", "yellow", "darkorchid1"), alpha = 0.20, #对不同组的着色
label.col = c("orange", "white", "darkorchid4", "white", "white", "white", "white", "white", "darkblue", "white",white", "white", "white", "darkgreen", "white"),#是对交集元素个数的数字的颜色
cex = 1.0, fontfamily = "serif", fontface = "bold", cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"), #字体粗细和颜色等
cat.cex = 0.8, cat.fontface = "bold",#标记文字的字体大小和粗细
cat.fontfamily = "serif")
但是原图是实现,数字标记为黑色,所以稍加修改:去掉虚线线性,去掉数字标记颜色,默认使用黑色实现。
venn.plot <- venn.diagram(
x = list( High.marine.Protein= vn$High.marine.Protein, Medium.fat = vn$Medium.fat, High.fat = vn$High.fat, Low.marine.protein = vn$Low.marine.protein ),
filename = 'C:/Users/Mr.R/Documents/ReproduceImages/Reproduction1 Core gut microbial communities are maintained by beneficial interactions and strain/VennDiagram.tiff',
col = "black", ,lwd = 1,
fill = c("cornflowerblue", "green", "yellow", "darkorchid1"),alpha = 0.20,
cex = 0.6, fontfamily = "serif", fontface = "bold",
cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"), cat.cex = 0.6,
cat.fontface = "bold",cat.fontfamily = "serif")
得到最终结果
image.png
网友评论