This repository has been archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-intro.Rmd
264 lines (181 loc) · 5.86 KB
/
01-intro.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# Introduction {#intro}
Suppose we have a list of genes.
```{r}
genes <- paste0("gene",1:1000)
set.seed(20210302)
gene_list <- list(A = sample(genes,100),
B = sample(genes,200),
C = sample(genes,300),
D = sample(genes,200))
library(dplyr)
```
## `VennDiagram`
`VennDiagram` [@R-VennDiagram] is currently the most popular Venn plot tool in R environment.
```{r}
library(VennDiagram)
VennDiagram <- venn.diagram(x = gene_list, filename = NULL)
cowplot::plot_grid(VennDiagram)
```
It provide basic functions to draw Euler plot.
```{r}
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"),
euler.d = TRUE
)
cowplot::plot_grid(venn.plot)
```
helper function to get Venn partitions.
```{r}
get.venn.partitions(gene_list) %>% dplyr::as_tibble()
```
```{r include=FALSE}
# delete log file
unlink("VennDiagram*.log")
```
## `colorfulVennPlot`
[@R-colorfulVennPlot]
This package can specify the filled color for each region, but the first required parameter is a numeric vector of length 15, with specific names in suitable order, which makes it is very complicated to setup and use.
Besides, the filled color need to be specified one by one, which is very complicated as well.
```{r}
library(colorfulVennPlot)
Colors <- c('red', 'yellow', 'green', 'pink', 'darkgreen','blue','lightblue','tan',
'yellowgreen','orange','purple','white','grey','plum','brown')
regions <- seq(15)
names(regions) <- c('1000', '0100', '1100', '0010', '1010', '0110', '1110', '0001',
'1001', '0101', '1101', '0011', '1011', '0111', '1111')
plotVenn4d(regions, Colors=Colors)
```
## `venn`
[@R-venn]
Using `venn` is very simple.
```{r}
library(venn)
venn(gene_list)
```
`venn` also support different shapes.
```{r}
venn(x = gene_list, ellipse = TRUE)
```
`venn` support `ggplot`, but it depends on `ggpolypath`, which is not popular.
```{r}
venn::venn(gene_list, ellipse = TRUE, ggplot = TRUE)
```
`venn` plots Venn diagram up to 7 sets.
```{r}
venn::venn(5)
```
```{r}
venn::venn(6)
```
```{r}
venn::venn(7)
```
`venn` accepts multiple format of input.
```{r}
intersections <- c('~A~B~C~D', '~A~B~CD', '~A~BC~D', '~A~BCD', '~AB~C~D', '~AB~CD', '~ABC~D', '~ABCD', 'A~B~C~D', 'A~B~CD', 'A~BC~D', 'A~BCD', 'AB~C~D', 'AB~CD', 'ABC~D', 'ABCD')
venn(intersections, zcol = colors()[sample(1:657, 16)])
venn("A*D, A*B*~C + B*C*~D", zcol = c("blue", "red"))
venn("AD, AB~C + BC~D", zcol = c("blue", "red"))
venn("1-----")
venn("100 + 110 + 101 + 111")
```
## `nVennR`
`nVennR` provides an interface for the `nVenn` algorithm [@perez-silvaNVennGeneralizedQuasiproportional2018]. This algorithm works for any number of sets, and usually yields pleasing and informative Venn diagrams with proportionality information.
```{r message=FALSE, warning=FALSE}
library(nVennR)
myNV <- plotVenn(gene_list)
```
```{r results="asis"}
cat(myNV$svg)
```
## `eulerr`
[@R-eulerr]
`eulerr` generates area-proportional euler diagrams that display set relationships (intersections, unions, and disjoints) with circles or ellipses.
Unlike Venn diagrams, which show all possible relations between different sets, the Euler diagram shows only relevant relationships.
Venn diagrams are a more restrictive form of Euler diagrams. A Venn diagram must contain all $2^n$ logically possible zones of overlap between its $n$ curves, representing all combinations of inclusion/exclusion of its constituent sets.
```{r}
library(eulerr)
venn_plot <- venn(gene_list)
plot(venn_plot)
```
```{r}
euler_plot <- euler(gene_list)
plot(euler_plot)
```
At the time of March 9th, 2021, it is possible to provide input to eulerr as either
a named numeric vector with set combinations as disjoint set combinations or unions (depending on how the argument type is set in euler()),
a matrix or data frame of logicals with columns representing sets and rows the set relationships for each observation,
a list of sample spaces, or
a table.
```{r}
# Input as a matrix of logicals
set.seed(1)
mat <- cbind(
A = sample(c(TRUE, TRUE, FALSE), 50, TRUE),
B = sample(c(TRUE, FALSE), 50, TRUE),
C = sample(c(TRUE, FALSE, FALSE, FALSE), 50, TRUE)
)
(fit2 <- euler(mat))
```
The diagnose function is good.
```{r}
error_plot(fit2)
```
## `venneuler`
[@R-venneuler]
`venneulerr` depends on JAVA runtime environment, which makes its installation is unbearable for non-JAVA users.
Besides, it only has one exported function, which doesn't support list input.
```{r}
library(venneuler)
combinations <- c(A=0.3, B=0.3, C=1.1, "A&B"=0.1, "A&C"=0.2, "B&C"=0.1 ,"A&B&C"=0.1,"D"=0.2,"C&D"=0.1)
vd <- venneuler(combinations)
plot(vd)
```
## `RVenn`
[@R-RVenn]
`RVenn` is a package for dealing with multiple sets, while the base R functions (`intersect`, `union` and `setdiff`) only work with two sets.
The functions overlap, unite and discern abstract away the details, so one can just construct the universe and choose the sets to operate by index or set name.
`RVenn` provide a `ggvenn()` function to draw 2-3 sets Venn diagram. In this case,
its advantages are mostly rely on set operation functions.
```{r}
library(RVenn)
ggvenn(Venn(gene_list[1:3]))
```
## `gplots`
[@R-gplots]
`gplots` provides various R programming tools for plotting data. It supports Venn plot up to five sets.
```{r}
library(gplots)
venn(gene_list)
```
## `ggVennDiagram`
[@R-ggVennDiagram]
```{r}
library(ggVennDiagram)
ggVennDiagram(gene_list)
```
## `ggvenn`
[@R-ggvenn]
```{r}
library(ggvenn)
ggvenn(gene_list)
```
`ggvenn` can show elements in polygon regions.
```{r}
a <- list(A = c("apple", "pear", "peach"),
B = c("apple", "lemon"))
ggvenn(a, show_elements = TRUE)
ggvenn(a, show_elements = TRUE, label_sep = "\n") # show elements in line
```