-
Notifications
You must be signed in to change notification settings - Fork 38
/
README.rmd
240 lines (167 loc) · 7.89 KB
/
README.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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "90%"
)
library("badger")
```
# ggVennDiagram
<!-- badges: start -->
`r badge_cran_download("ggVennDiagram", type = "grand-total")`
`r badge_cran_download("ggVennDiagram", type = "last-month")`
`r badge_doi("10.1002/imt2.177", "blue")`
`r badge_cran_release("ggVennDiagram","green")`
`r badge_devel(color = "green")`
`r badge_codecov(token = "c365345d-e34c-40f6-b2c0-881b5b2841e7")`
<!-- badges: end -->
'`ggVennDiagram`' enables fancy Venn plot with 2-7 sets and generates publication quality figure. It also support upset plot with unlimited number of sets from version 1.4.4.
## Installation
You can install the released version of ggVennDiagram from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("ggVennDiagram")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("gaospecial/ggVennDiagram")
```
## Citation
If you find **ggVennDiagram** is useful and used it in academic papers, you may cite this package as:
Gao, C.-H., Chen, C., Akyol, T., Dușa, A., Yu, G., Cao, B., and Cai, P. (2024). ggVennDiagram: intuitive Venn diagram software extended. [iMeta](https://onlinelibrary.wiley.com/journal/2770596x) 3, 69. doi: [10.1002/imt2.177](https://onlinelibrary.wiley.com/doi/full/10.1002/imt2.177).
## Features
![](https://vnote-1251564393.cos.ap-chengdu.myqcloud.com/picgo/202403141008626.png)
**Notes**
The ggVennDiagram Shiny app can be accessed at Shinyapps.io (https://bio-spring.shinyapps.io/ggVennDiagram), or `ggVennDiagram::launch_app()` in local machine.
The [TBtools](https://github.com/CJ-Chen/TBtools-II) plugin can be accessed through its plugin store.
## Example
`ggVennDiagram` maps the fill color of each region to quantity, allowing us to visually observe the differences between different parts.
```{r}
library(ggVennDiagram)
genes <- paste("gene",1:1000,sep="")
set.seed(20231214)
x <- list(A=sample(genes,300),
B=sample(genes,525),
C=sample(genes,440),
D=sample(genes,350))
```
```{r include=FALSE}
devtools::load_all()
```
`ggVennDiagram` return a `ggplot` object, the fill/edge colors can be further modified with `ggplot` functions.
```{r}
library(ggplot2)
ggVennDiagram(x) + scale_fill_gradient(low="grey90",high = "red")
ggVennDiagram(x, set_color = c("blue","red","green","purple"))
```
`ggVennDiagram` support 2-7 dimension Venn plot. The generated figure is generally ready for publish. The main function `ggVennDiagram()` will check how many items in the first parameter and call corresponding function automatically.
The parameter `category.names` is set names. And the parameter `label` can label how many items are included in each parts.
```{r}
ggVennDiagram(x,category.names = c("Stage 1","Stage 2","Stage 3", "Stage4"))
ggVennDiagram(x,category.names = c("Stage 1","Stage 2","Stage 3", "Stage4"), label = "none")
```
Set `label_alpha = 0` to remove label background.
```{r}
ggVennDiagram(x, label_alpha=0)
```
## Showing intersection values
*Note: you need to install the GitHub version to enable these functions.*
We implemented the `process_region_data()` to get intersection values.
```{r}
y <- list(
A = sample(letters, 8),
B = sample(letters, 8),
C = sample(letters, 8),
D = sample(letters, 8)
)
process_region_data(Venn(y))
```
If only several items were included, intersections may also be viewed interactively by `plotly` method (if you have two many items, this is useless).
```{r eval=FALSE}
ggVennDiagram(y, show_intersect = TRUE)
```
In web browser or RStudio, you will get:
```{r echo=FALSE}
knitr::include_graphics("https://vnote-1251564393.cos.ap-chengdu.myqcloud.com/typora-img/intersection.gif")
```
# Customizing your plot
There are three components in a Venn plot: 1) the set labels; 2) the edge of sets;
and 3) the filling regions and labels (optional) of each parts. We separately stored these data in a structured `VennPlotData` object, in which labels, edges and regions are stored as data frames.
In general, `ggVennDiagram()` plot a Venn in three steps:
- get the coordinates of a applicable shape from internal `shapes` datasets.
- calculate sub regions of sets, including both the shape regions and sets members,
and return a `VennPlotData` object that includes all necessary definitions.
We implement a number of set operations functions to do this job.
- plot using `ggplot2` functions.
Please check `vignette("fully-customed", package = "ggVennDiagram")` for more information.
# Venn Diagram for more than four sets
If you have reviewed my codes, you may find it is easy to support Venn Diagram for more than four sets,
as soon as you find a ideal parameter to generate more circles or ellipses in the plot.
The key point is to let the generated ellipses have exactly one intersection for each combination.
## Venn Diagram of up to seven sets
From v1.0, `ggVennDiagram` can plot up to seven dimension Venn plot. Please note that the shapes for this five sets diagram, as well as those for six and seven sets, are imported from the original package [`venn`](https://CRAN.R-project.org/package=venn) authored by Adrian Dușa.
However, Venn Diagram for more than four sets may be meaningless in some conditions,
as some parts may be omitted in such ellipses. Therefore, it is only useful in specific conditions.
For example, if the set intersection of all group are extremely large, you may use several
ellipses to draw a "flower" to show that.
```{r eval=FALSE}
x <- list(A=sample(genes,300),
B=sample(genes,525),
C=sample(genes,440),
D=sample(genes,350),
E=sample(genes,200),
F=sample(genes,150),
G=sample(genes,100))
# two dimension Venn plot
ggVennDiagram(x[1:2],label = "none")
# three dimension Venn plot
ggVennDiagram(x[1:3],label = "none")
# four dimension Venn plot
ggVennDiagram(x[1:4],label = "none")
# five dimension Venn plot
ggVennDiagram(x[1:5],label = "none")
# six dimension Venn plot
ggVennDiagram(x[1:6],label = "none")
# seven dimension Venn plot
ggVennDiagram(x,label = "none")
```
```{r echo=FALSE, fig.asp=1.2,fig.width=6}
set.seed(20210507)
x <- list(A = sample(genes,100),
B = sample(genes,150),
C = sample(genes,200),
D = sample(genes,250),
E = sample(genes,300),
F = sample(genes,350),
G = sample(genes,400))
plots <- lapply(2:7, function(i) ggVennDiagram(x[1:i],label = "none",edge_size = 0.5) +
labs(title = paste("sets = ", i)) +
scale_fill_distiller(palette = "RdBu") +
theme(legend.position = "none",
title = element_text(hjust = 0.5)))
cowplot::plot_grid(plotlist = plots, ncol = 2)
```
## Native support of upset plot
From version 1.4.4, `ggVennDiagram` supports unlimited number of sets, as it can draw a plain upset plot automatically when number of sets is more than 7.
```{r}
# add an extra member in list
x$H = sample(genes,500)
ggVennDiagram(x)
```
Upset plot can also be used by setting `force_upset = TRUE`.
```{r}
ggVennDiagram(x[1:4], force_upset = TRUE, order.set.by = "name", order.intersect.by = "none")
```
Since upset plot is consisted with upper panel and lower panel, and left panel and right panel, the appearance should be adjusted with different conditions. We provide two parameters, which are `relative_height` and `relative_width` to do this.
For example, if we want to give more space to lower panel, just change the `relative_height` from 3 (the default) to 2.
```{r}
venn = Venn(x)
plot_upset(venn, nintersects = 30, relative_height = 2, relative_width = 0.3)
```
# Reference
Adrian Dușa (2024) _venn: Draw Venn Diagrams_, R package version 1.12. <https://CRAN.R-project.org/package=venn>.