Skip to content

Yixf-Self/ggVennDiagram

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ggVennDiagram

ggVennDiagram’ enables fancy Venn plot with 2-4 sets and generates publication quality figure. It is the first software that can automatically fill different colors to each part of a Venn diagram.

Installation

You can install the released version of ggVennDiagram from CRAN with (under evaluation in CRAN):

install.packages("ggVennDiagram")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("gaospecial/ggVennDiagram")

Example

ggVennDiagram maps the fill color of each region to quantity, allowing us to visually observe the differences between different parts.

library(ggVennDiagram)
genes <- paste("gene",1:1000,sep="")
set.seed(20190708)
x <- list(A=sample(genes,300),B=sample(genes,525),C=sample(genes,440),D=sample(genes,350))

# four dimension Venn plot
ggVennDiagram(x)

# three dimension Venn plot
ggVennDiagram(x[1:3])

# two dimension Venn plot
ggVennDiagram(x[1:2])

ggVennDiagram return a ggplot object, which can be further modified with ggplot functions.

library(ggplot2)
ggVennDiagram(x) + scale_fill_gradient(low="blue",high = "red")
#> Scale for 'fill' is already present. Adding another scale for 'fill',
#> which will replace the existing scale.

ggVennDiagram(x,lty="dashed",color="black",size=2) + scale_fill_gradient(low="white",high = "red")
#> Scale for 'fill' is already present. Adding another scale for 'fill',
#> which will replace the existing scale.

ggVennDiagram now support 2-4 dimension Venn plot. The generated figure is generally ready for publish. The main function ggVennDiagram() will check how many items in the first paramenter and call corresponding function automatically.

The parameter category.names reprents set names. And the parameter label can label how many items are included in each parts.

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 = NULL)

Set label_alpha = 0 to remove label background

ggVennDiagram(x, label_alpha=0)

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.

However, Venn Diagram for more than four sets may be meaningfulless in some conditions, as some parts may be omittd 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.

ggVennDiagram” 诞生记

@GuangchuangYu 的公众号下面,我投稿了一篇文章,介绍了 “ggVennDiagram” 包开发的始末,有兴趣的同学可以移步至此查看。

About

A 'ggplot2' implement of Venn Diagram

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • R 100.0%