‘ggVennDiagram
’ enables fancy Venn plot with 2-7 sets
and generates publication quality figure.
You can install the released version of ggVennDiagram from CRAN with:
install.packages("ggVennDiagram")
And the development version from GitHub with:
# install.packages("devtools")
::install_github("gaospecial/ggVennDiagram") devtools
Generate example data.
<- paste0("gene",1:1000)
genes set.seed(20210302)
<- list(A = sample(genes,100),
gene_list B = sample(genes,200),
C = sample(genes,300),
D = sample(genes,200))
library(ggVennDiagram)
library(ggplot2)
If you use long category names in Venn plot, labels may be cropped by plot borders. To avoid this, just use a ggplot trick to expand x axis.
<- ggVennDiagram(gene_list,
p1 category.names = c("a very long name","short name","name","another name"))
p1
# expand axis to show long set labels
+ scale_x_continuous(expand = expansion(mult = .2)) p1
When intersection values only have several members,
ggVennDiagram
is efficient to show the values in
places.
set.seed(0)
<- lapply(sample(6:10, size = 4), function(x){
small_list sample(letters,x)
})
ggVennDiagram(small_list,
category.names = LETTERS[1:4],
show_intersect = TRUE)
#> Warning: Ignoring unknown aesthetics: text
ggVennDiagram(gene_list, set_color = c("blue","black","red","green"))
ggVennDiagram(gene_list, set_size = 8)
ggVennDiagram(gene_list, label = "count")
ggVennDiagram(gene_list, label = "percent")
ggVennDiagram(gene_list, label_percent_digit = 1, label = "percent")
ggVennDiagram(gene_list, label_alpha = 0)
- Method 2: use geom_text()
ggVennDiagram(gene_list, label_geom = "text")
ggVennDiagram(gene_list, label_color = "firebrick", label_size = 4)
ggVennDiagram(gene_list, edge_lty = "dashed", edge_size = 1)
library(ggplot2)
<- ggVennDiagram(gene_list)
p
# Red Blue
+ scale_fill_distiller(palette = "RdBu") p
# Reds
+ scale_fill_distiller(palette = "Reds", direction = 1) p
+ scale_color_brewer(palette = "Set1") p
Some other palletes are:
::display.brewer.all() RColorBrewer
+ labs(title = "Four sets Venn Diagram",
p subtitle = "generated by `ggVennDiagram`",
caption = Sys.Date())