From https://blog.csdn.net/u011808596/article/details/80974250
# 先安裝各個包
futile.logger - R中類似log4j的日志記錄包. 官網:https://github.com/zatonovo/futile.logger
log4r - R中的log4j接口. 官網:https://github.com/johnmyleswhite/log4r
logging - 一個在R中實現log4j的日志處理包. 官網:https://cran.r-project.org/web/packages/logging/index.html
# install.packages("VennDiagram")
library(grid)
library(futile.logger)
library(VennDiagram)
==============================================
已知各個數據集的個數,並且交叉個數來制作韋恩圖
兩個數據集:
venn.plot <- draw.pairwise.venn(
area1 = 100, #區域1的數
area2 = 70, #區域2的數
cross.area = 68, #交叉數
category = c("First", "Second"),#分類名稱
fill = c("blue", "red"),#區域填充顏色
lty = "blank", #區域邊框線類型
cex = 2, #區域內部數字的字體大小
cat.cex = 2, #分類名稱字體大小
cat.pos = c(285, 105), #分類名稱在圓的位置,默認正上方,通過角度進行調整
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);
三個數據集
# A more complicated diagram
venn.plot <- draw.triple.venn(
area1 = 65,
area2 = 75,
area3 = 85,
n12 = 35,
n23 = 15,
n13 = 25,
n123 = 5,
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);#畫圖展示
# Writing to file
tiff(filename = "Triple_Venn_diagram.tiff", compression = "lzw"); #保存圖片
dev.off();
四個數據集:
# Reference four-set diagram
venn.plot <- draw.quad.venn(
area1 = 72,
area2 = 86,
area3 = 50,
area4 = 52,
n12 = 44,
n13 = 27,
n14 = 32,
n23 = 38,
n24 = 32,
n34 = 20,
n123 = 18,
n124 = 17,
n134 = 11,
n234 = 13,
n1234 = 6,
category = c("First", "Second", "Third", "Fourth"),
fill = c("orange", "red", "green", "blue"),
lty = "dashed",
cex = 2,
cat.cex = 2,
cat.col = c("orange", "red", "green", "blue")
);
grid.draw(venn.plot);#畫圖展示
# Writing to file
tiff(filename = "Quad_Venn_diagram.tiff", compression = "lzw");#保存圖片
dev.off();退出畫圖
五個數據集:
# Reference five-set diagram
venn.plot1 <- draw.quintuple.venn(
area1 = 301,
area2 = 321,
area3 = 311,
area4 = 321,
area5 = 301,
n12 = 188,
n13 = 191,
n14 = 184,
n15 = 177,
n23 = 194,
n24 = 197,
n25 = 190,
n34 = 190,
n35 = 173,
n45 = 186,
n123 = 112,
n124 = 108,
n125 = 108,
n134 = 111,
n135 = 104,
n145 = 104,
n234 = 111,
n235 = 107,
n245 = 110,
n345 = 100,
n1234 = 61,
n1235 = 60,
n1245 = 59,
n1345 = 58,
n2345 = 57,
n12345 = 31,
category = c("A", "B", "C", "D", "E"),
fill = c("dodgerblue", "goldenrod1", "darkorange1", "seagreen3", "orchid3"),
cat.col = c("dodgerblue", "goldenrod1", "darkorange1", "seagreen3", "orchid3"),
cat.cex = 2,
margin = 0.05,
cex = c(1.5, 1.5, 1.5, 1.5, 1.5, 1, 0.8, 1, 0.8, 1, 0.8, 1, 0.8, 1, 0.8,
1, 0.55, 1, 0.55, 1, 0.55, 1, 0.55, 1, 0.55, 1, 1, 1, 1, 1, 1.5),
ind = TRUE
);
grid.draw(venn.plot);#畫圖展示
==============================================
通過數據列表進行制作圖:
兩個數據集:
# a more elaborate two-set Venn diagram with title and subtitle
venn.plot <- venn.diagram(
x = list(
"A" = 1:100,
"B" = 96:140
),
filename = "c:\\Venn_22set_complex.tiff",
col = "transparent",
fill = c("red", "green"),
cex = 2.5,
cat.cex = 2.5,
rotation.degree = 0,
main = "Complex Venn Diagram",
main.cex = 2,
sub.cex = 1,
alpha = 0.50
);
三個數據集:
A <- sample(1:1000, 400, replace = FALSE);
B <- sample(1:1000, 600, replace = FALSE);
C <- sample(1:1000, 350, replace = FALSE);
venn.plot <- venn.diagram(
#數據列表
x = list(
A = A,
B = B,
C = C
),
filename ="C:\\1.tiff", #保存路徑
height = 450,
width = 450,
resolution =300,
#imagetype="png",
col = "transparent", #指定圖形的圓周邊緣顏色 transparent 透明
fill = c("cornflowerblue", "green", "darkorchid1"), #填充顏色
alpha = 0.50, #透明度
label.col = c("orange", "white", "darkorchid4", "white",
"white", "darkgreen", "white"),
cex = 0.45, #每個區域label名稱的大小
fontfamily = "serif", #字體
fontface = "bold", #字體格式
cat.col = c("darkblue", "darkgreen", "darkorchid4"), #分類顏色
cat.cex = 0.45, #每個分類名稱大小
cat.pos = c(100, 260, 0), #
cat.dist = c(0.07, 0.07, 0.05), #
cat.fontfamily = "serif", #分類字體
rotation.degree =180, #旋轉角度
margin = 0.2 #在網格單元中給出圖周圍空白量的編號
);
可以不保存查看圖片,但是效果不佳(命令如下,但是需要首先把filename設置為(filename=NULL))
grid.draw(venn.plot);
dev.off();
四個數據集:
#sample為抽樣函數,首先指定抽樣范圍,然后制定抽樣個數,最后指定是否允許同樣的抽樣值
A <- sample(1:1000, 400, replace = FALSE);
B <- sample(1:1000, 600, replace = FALSE);
C <- sample(1:1000, 350, replace = FALSE);
D <- sample(1:1000, 550, replace = FALSE);
E <- sample(1:1000, 375, replace = FALSE);
venn.plot <- venn.diagram(
#數據列表
x = list(
A = A,
D = D,
B = B,
C = C
),
filename = "Venn_4set_pretty.tiff", #保存路徑
col = "transparent", #指定圖形的圓周邊緣顏色 transparent 透明
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 = 1.5, #每個區域label名稱的大小
fontfamily = "serif", #字體
fontface = "bold", #字體格式
cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"), #分類顏色
cat.cex = 1.5, #每個分類名稱大小
cat.pos = 0, #
cat.dist = 0.07, #
cat.fontfamily = "serif", #分類字體
rotation.degree = 270, #旋轉角度
margin = 0.2 #在網格單元中給出圖周圍空白量的編號
);
五個數據集:
A <- sample(1:1000, 400, replace = FALSE);
B <- sample(1:1000, 600, replace = FALSE);
C <- sample(1:1000, 350, replace = FALSE);
D <- sample(1:1000, 550, replace = FALSE);
E <- sample(1:1000, 375, replace = FALSE);
venn.plot <- venn.diagram(
x = list(
A = A,
B = B,
C = C,
D = D,
E = E
),
filename = "c:\\Venn_5set_pretty.tiff",
col = "black",
fill = c("dodgerblue", "goldenrod1", "darkorange1", "seagreen3", "orchid3"),
alpha = 0.50,
cex = c(1.5, 1.5, 1.5, 1.5, 1.5, 1, 0.8, 1, 0.8, 1, 0.8, 1, 0.8,
1, 0.8, 1, 0.55, 1, 0.55, 1, 0.55, 1, 0.55, 1, 0.55, 1, 1, 1, 1, 1, 1.5),
cat.col = c("dodgerblue", "goldenrod1", "darkorange1", "seagreen3", "orchid3"),
cat.cex = 1.5,
cat.fontface = "bold",
margin = 0.05
);
==============================================
畫文氏圖:
https://www.cnblogs.com/emanlee/p/3931831.html