有时候我们需要用圆圈来表示两个集合的关系,在R语言里可以使用plotrix包来作简单的维恩(vene)图,代码如下: install.packages('plotrix')#安装plotrix包 library('plotrix')#加载plotrix包 par(ann=F)#默认是注释轴标题和标题,FALSE则不注释 plot(0:10,seq(0,10,length=11),type='n',axes=F)#打开定义好的图层,并隐藏图和坐标 draw.circle(2,5,2)#作对应坐标的圆 draw.circle(4,5,2)#作对应坐标的圆 text(1,7,labels='30%',col='black',font=2)#设置第一个圆的标签 text(3,7,labels='40%',col='black',font=2)#设置两圆交界处的标签 text(5,7,labels='30%',col='black',font=2)#设置第三个圆的标签 text(2,4,'A')#设置第一个下标签 text(5,4,'B')#设置第二个下标签 text(3,2,labels='Venn picture',font=2,cex=2)#设置总标题
绘制复杂的维恩图使用VennDiagram包里的venn.diagram函数,具体的查看帮助,下面为其中的一个例子,供大家参考。
绘制ABCDE四个图的交集,图像默认保存在运行路径,可以输入getwd()找到图像保存的位置,或者自己设置保存路径。
install.packages('VennDiagram')#安装包,注意大小写
library(venndiagram)#加载包,小写 venn.plot <->-> x = list( A = A, D = D, B = B, C = C ), filename = 'Venn_4set_pretty.tiff', 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 = 0, cat.dist = 0.07, cat.fontfamily = 'serif', rotation.degree = 270, margin = 0.2 )#各参数设置
结果如下:
版权声明:本公众号的内容部分来自互联网,转载请注明原文链接和作者,如有侵权或出处有误请联系我们。
|