其他
简单的韦恩图画法
韦恩图是非常常见的类型,今天学习下常见的韦恩图画图方法。
今天先介绍VennDigram
包,也是我平常画韦恩图最常用的R包。
先随机生成几个数据集。
set1 <- sample(1:1000,300,replace = F)
set2 <- sample(1:1000,130,replace = F)
set3 <- sample(1:1000,300,replace = F)
set4 <- sample(1:1000,300,replace = F)
2个数据集
library(VennDiagram)
## 载入需要的程辑包:grid
## 载入需要的程辑包:futile.logger
s1 <- list(set1 = set1,
set2 = set2)
v1 <- venn.diagram(x = s1, filename = NULL)
cowplot::plot_grid(v1)
你如果直接这样写,就会自动保存文件到本地:
venn.diagram(x = s1, filename = "name.png",
height = 450,
width = 450,
resolution =300,
imagetype="png"
)
美化一下(美化后的图依然还是很丑哈,纯粹为了演示下各个参数的用法):
v1 <- venn.diagram(x = s1, filename = NULL, # 直接给一个名称会自动保存文件到本地
scaled = T, # 根据比例显示大小
alpha=c(0.8, 0.8),
fill=c("#0073C2FF","#EFC000FF"), # 配色
cat.dist = c(0.03,0.03), # 名称距离圆圈的远近
cat.pos = c(0,0), # 名称相对于圆圈的位置,角度
cat.cex = c(2,2), #名称字体大小
lwd = 2, # 圆圈线条粗细
lty = 1, # 圆圈线条形状
col = c("black","red"), #圆圈线条颜色
label.col = c("black","blue","red"), # 数字颜色,注意数量
cex = 2, # 数字大小
ext.text = T, # 增加指示线和标签
ext.percent = c(0.9,0.5,0.4), # 出现指示线和标签的条件
ext.dist = c(0.01,0.01),
ext.length = 0.8
)
cowplot::plot_grid(v1)
上面列出的参数应该就是大家最常用的了,很多都需要根据自己的实际情况不断调整才能达到很好看的效果。
3个数据集
s2 <- list(
set1 = set1,
set2 = set2,
set3 = set3
)
v2 <- venn.diagram(x = s2, filename = NULL,
col="white",
fill=c(colors()[616], colors()[38], colors()[468]),
alpha=c(0.6, 0.6, 0.6),
lwd=c(1, 1, 1),
cex=2,
cat.dist=c(0.05, 0.05, -0.45),
cat.pos=c(0, 0, 0),
cat.cex=2
)
cowplot::plot_grid(v2)
4个数据集
## 4个数据集
s3 <- list(
set1 = set1,
set2 = set2,
set3 = set3,
set4 = set4
)
v3 <- venn.diagram(x = s3, filename = NULL,
#height = 450,
#width = 450,
#resolution =300,
#imagetype="png",
col="transparent",
fill=c("cornflowerblue","green","yellow","darkorchid1"),
alpha = 0.50,
cex=2,
cat.cex=2
)
cowplot::plot_grid(v3)
再来一些细节调整:
s4 <- list(
A = set1,
B = set2,
C = set3,
D = set4
)
venn.plot <- venn.diagram(
x = s4,
filename = NULL,
col = "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,
fontfamily = "serif",
fontface = "bold",
cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"),
cat.cex = 1.5,
cat.pos = c(30,150,70,110),
cat.dist = c(0.2,0.2,0.1,0.1),
cat.fontfamily = "serif",
rotation.degree = 270, # 旋转图形
margin = 0.1 # 调整边距
)
cowplot::plot_grid(venn.plot)
5个数据集当然也是可以的,5个就是这个包的上限,就不再演示了。
但是这个包每运行一次就会产生一个本地日志文件,我不能忍,烦的要命!
以上就是今天的内容,希望对你有帮助哦!欢迎点赞、在看、关注、转发!
欢迎在评论区留言或直接添加我的微信!
欢迎关注公众号:医学和生信笔记
“医学和生信笔记 公众号主要分享:1.医学小知识、肛肠科小知识;2.R语言和Python相关的数据分析、可视化、机器学习等;3.生物信息学学习资料和自己的学习笔记!
往期回顾
我的个人博客上线了!
你没见过的ggplot2另类画图!
2行代码重命名上百个列名!
应用预测建模:开篇