比例韦恩图

2022-11-15 11:24:10 浏览数 (2)

之前介绍了巨多画韦恩图和upset plot的R包,今天再介绍一个可以按照比例画不同大小圆圈韦恩图的R包:eulerr

安装

代码语言:javascript复制
install.packages("eulerr")

使用

输入数据可以是一个列表,每一个元素代表一个数据集。这种方式在我看来是最简单、最好理解的。

代码语言:javascript复制
library(eulerr)

df1 <- list(a = c(1, 2, 3, 4, 5, 6, 7),
            b = c(1, 8, 5),
            c = c(1, 9, 4,5),
            d = c(10))

自带一个venn()函数,可以画普通的韦恩图,默认配色还不错,默认配色来自于同一个作者的另一个R包:qualpalr,感兴趣的可以去看看。

代码语言:javascript复制
plot(venn(df1))

plot of chunk unnamed-chunk-3

使用euler()之后就变成了比例韦恩图,形状可选circle或者ellipse.

代码语言:javascript复制
plot(euler(df1, shape = "circle"), quantities = TRUE)

可以修改填充色,边框色,标签字体颜色、大小等。

代码语言:javascript复制
plot(euler(df1),
     
     # 数字大小
     quantities = list(cex=3), 
     
     # 填充色
     fills = list(fill=c("red","blue","yellow","steelblue",
                         "skyblue","orange","firebrick","grey")),
     
     # 边框
     edges = list(col="purple",lty = 1:4,lwd=2),
     
     # 标签
     labels = list(col="darkgreen",cex=3)
     )

输入数据还可以是一个向量,包含各个数据集元素个数以及交集个数。

代码语言:javascript复制
plot(euler(c("a" = 3491, 
             "b" = 1058, 
             "c" = 2213,
             
             "a&b" = 120, 
             "a&c" = 114, 
             "b&c" = 132,
             "a&b&c" = 50),
           ),
     quantities = T
     )

image-20220812221903324

输入数据还可以是一个逻辑值矩阵或数据框,全部用T/F表示,每一列是一个数据集。

fruits数据集演示下:

代码语言:javascript复制
# 数据集长这样
fruits
##     banana apple orange    sex   age
## 1    FALSE FALSE  FALSE female adult
## 2    FALSE FALSE  FALSE   male child
## 3     TRUE  TRUE  FALSE   male adult
## 4     TRUE FALSE  FALSE   male adult
## 5    FALSE FALSE  FALSE   male adult
## 6     TRUE  TRUE  FALSE female adult
## 7     TRUE  TRUE  FALSE   male child
## 8     TRUE  TRUE  FALSE female adult
## 9     TRUE FALSE  FALSE   male child
## 10   FALSE FALSE  FALSE   male adult
## 11   FALSE  TRUE   TRUE   male adult
## 12   FALSE FALSE  FALSE   male child
## 13    TRUE  TRUE   TRUE female adult
## 14   FALSE FALSE   TRUE female adult
## 15    TRUE  TRUE   TRUE   male adult
## 16   FALSE FALSE  FALSE   male child
## 17    TRUE  TRUE  FALSE   male child
## 18    TRUE  TRUE   TRUE   male child
## 19   FALSE FALSE   TRUE female adult
## 20    TRUE  TRUE  FALSE female adult
## 21    TRUE FALSE  FALSE female child
## 22   FALSE FALSE  FALSE   male adult
## 23    TRUE  TRUE  FALSE   male adult
## 24   FALSE FALSE  FALSE female child
## 25   FALSE FALSE   TRUE female child
## 26   FALSE FALSE  FALSE female child
## 27   FALSE FALSE  FALSE female child
## 28   FALSE FALSE  FALSE female adult
## 29    TRUE  TRUE  FALSE   male adult
## 30   FALSE FALSE  FALSE female adult
## 31   FALSE FALSE  FALSE female adult
## 32    TRUE  TRUE  FALSE   male child
## 33   FALSE FALSE  FALSE   male child
## 34   FALSE FALSE  FALSE female adult
## 35    TRUE FALSE  FALSE   male child
## 36    TRUE  TRUE  FALSE   male adult
## 37    TRUE  TRUE  FALSE   male adult
## 38   FALSE FALSE  FALSE   male child
## 39    TRUE FALSE  FALSE female child
## 40   FALSE FALSE  FALSE female adult
## 41    TRUE  TRUE  FALSE female child
## 42    TRUE  TRUE  FALSE   male child
## 43    TRUE  TRUE   TRUE female adult
## 44    TRUE  TRUE  FALSE   male adult
## 45    TRUE  TRUE  FALSE female child
## 46    TRUE  TRUE  FALSE   male child
## 47   FALSE FALSE  FALSE   male child
## 48   FALSE FALSE  FALSE   male adult
## 49    TRUE  TRUE  FALSE   male child
## 50    TRUE FALSE   TRUE female child
## 51   FALSE FALSE  FALSE   male adult
## 52    TRUE  TRUE   TRUE   male child
## 53   FALSE FALSE  FALSE female child
## 54   FALSE FALSE  FALSE   male child
## 55   FALSE FALSE  FALSE female child
## 56   FALSE FALSE  FALSE   male adult
## 57   FALSE FALSE  FALSE female adult
## 58    TRUE  TRUE  FALSE   male adult
## 59    TRUE  TRUE  FALSE female adult
## 60   FALSE FALSE   TRUE   male child
## 61    TRUE  TRUE  FALSE   male child
## 62   FALSE  TRUE  FALSE   male child
## 63   FALSE FALSE  FALSE female child
## 64   FALSE FALSE  FALSE   male child
## 65    TRUE FALSE  FALSE female child
## 66   FALSE FALSE  FALSE female adult
## 67   FALSE FALSE  FALSE   male adult
## 68    TRUE  TRUE   TRUE female child
## 69   FALSE FALSE  FALSE female child
## 70    TRUE  TRUE  FALSE   male adult
## 71   FALSE FALSE  FALSE   male child
## 72    TRUE FALSE  FALSE female adult
## 73   FALSE  TRUE  FALSE female adult
## 74   FALSE FALSE  FALSE   male child
## 75   FALSE FALSE  FALSE   male child
## 76    TRUE FALSE  FALSE   male child
## 77    TRUE  TRUE  FALSE   male adult
## 78   FALSE FALSE  FALSE female child
## 79    TRUE  TRUE  FALSE   male child
## 80    TRUE FALSE  FALSE   male adult
## 81   FALSE FALSE  FALSE   male adult
## 82    TRUE  TRUE  FALSE female child
## 83   FALSE  TRUE  FALSE female adult
## 84   FALSE FALSE  FALSE female adult
## 85    TRUE FALSE  FALSE   male adult
## 86   FALSE FALSE  FALSE   male adult
## 87    TRUE  TRUE  FALSE female child
## 88   FALSE FALSE  FALSE female child
## 89   FALSE  TRUE  FALSE   male adult
## 90   FALSE FALSE  FALSE female child
## 91   FALSE FALSE  FALSE   male child
## 92   FALSE FALSE  FALSE   male adult
## 93    TRUE  TRUE   TRUE female child
## 94    TRUE FALSE  FALSE female child
## 95    TRUE  TRUE  FALSE   male child
## 96    TRUE  TRUE  FALSE   male child
## 97   FALSE FALSE  FALSE female child
## 98   FALSE  TRUE  FALSE   male adult
## 99    TRUE  TRUE  FALSE   male adult
## 100   TRUE  TRUE   TRUE   male child
代码语言:javascript复制
plot(euler(fruits[, 1:3], shape = "ellipse"), quantities = TRUE)

以上就是今天的内容~

0 人点赞