├── .github ├── .gitignore └── workflows │ └── pkgdown.yaml ├── cran-comments.md ├── vignettes ├── .gitignore ├── VennCalculator.Rmd ├── using-new-shapes.Rmd ├── using-ggVennDiagram.Rmd └── fully-customed.Rmd ├── R ├── sysdata.rda ├── vensets.R ├── launch_app.R ├── check_pakage.R ├── regions.R ├── view_shape.R ├── plot_shapes.R ├── get_shape.R ├── classVenn.R ├── process_data.R ├── setOperations.R ├── ggVennDiagram.R └── upset_plot.R ├── tests ├── testthat.R └── testthat │ ├── test-4d-venn.R │ ├── test-class-Venn.R │ ├── test-memory_usage.R │ └── test-upset.R ├── inst ├── shiny │ ├── www │ │ ├── favicon.ico │ │ └── shinyApp.css │ └── shinyApp.R └── cli │ └── run_ggVennDiagram.R ├── CRAN-SUBMISSION ├── man ├── figures │ ├── README-unnamed-chunk-10-1.png │ ├── README-unnamed-chunk-11-1.png │ ├── README-unnamed-chunk-12-1.png │ ├── README-unnamed-chunk-13-1.png │ ├── README-unnamed-chunk-14-1.png │ ├── README-unnamed-chunk-3-1.png │ ├── README-unnamed-chunk-3-2.png │ ├── README-unnamed-chunk-4-1.png │ ├── README-unnamed-chunk-4-2.png │ ├── README-unnamed-chunk-5-1.png │ ├── README-unnamed-chunk-5-2.png │ └── README-unnamed-chunk-6-1.png ├── vensets.Rd ├── launch_app.Rd ├── get_shapes.Rd ├── combinations.Rd ├── all_identical.Rd ├── get_shape_by_id.Rd ├── slice_idx.Rd ├── plotData_add_venn.Rd ├── plot_shape_edge.Rd ├── separate_longer_delim.Rd ├── print.Rd ├── get_shape_data.Rd ├── plot_shapes.Rd ├── shapes.Rd ├── unite.Rd ├── overlap.Rd ├── discern_overlap.Rd ├── venn_plot_data.Rd ├── process_data.Rd ├── discern.Rd ├── process_upset_data.Rd ├── Venn-class.Rd ├── venn_data.Rd ├── VennPlotData.Rd ├── plot_venn.Rd ├── upset-plot.Rd └── ggVennDiagram.Rd ├── .gitignore ├── ggVennDiagram.Rproj ├── .Rbuildignore ├── NAMESPACE ├── _pkgdown.yml ├── roadmap.md ├── DESCRIPTION ├── data-raw └── shapes.R ├── NEWS.md ├── README.rmd ├── README.md ├── less-dependency.Rmd └── LICENSE.md /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | regular update 2 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | ggVennDiagram.Rproj 4 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/R/sysdata.rda -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(ggVennDiagram) 3 | 4 | test_check("ggVennDiagram") 5 | -------------------------------------------------------------------------------- /inst/shiny/www/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/inst/shiny/www/favicon.ico -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 1.5.4 2 | Date: 2025-06-21 07:14:54 UTC 3 | SHA: e757cb221132eb505818bb98def2b74f8248282a 4 | -------------------------------------------------------------------------------- /R/vensets.R: -------------------------------------------------------------------------------- 1 | #' Import venn shape coordinates 2 | #' 3 | #' @return a data frame 4 | vensets = function(){ 5 | venn::getSets() 6 | } 7 | -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-3-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-4-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-5-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gaospecial/ggVennDiagram/HEAD/man/figures/README-unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | inst/doc 6 | /doc/ 7 | /Meta/ 8 | docs 9 | .DS_Store 10 | rsconnect 11 | -------------------------------------------------------------------------------- /tests/testthat/test-4d-venn.R: -------------------------------------------------------------------------------- 1 | test_that("plot 4d Venn", { 2 | genes <- paste("gene",1:1000,sep="") 3 | set.seed(20210408) 4 | x <- list(A=sample(genes,300),B=sample(genes,525),C=sample(genes,440),D=sample(genes,350)) 5 | p <- ggVennDiagram(x) 6 | expect_is(p, "ggplot") 7 | }) 8 | -------------------------------------------------------------------------------- /man/vensets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vensets.R 3 | \name{vensets} 4 | \alias{vensets} 5 | \title{Import venn shape coordinates} 6 | \usage{ 7 | vensets() 8 | } 9 | \value{ 10 | a data frame 11 | } 12 | \description{ 13 | Import venn shape coordinates 14 | } 15 | -------------------------------------------------------------------------------- /man/launch_app.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/launch_app.R 3 | \name{launch_app} 4 | \alias{launch_app} 5 | \title{Launch Reactor Data Shiny App} 6 | \usage{ 7 | launch_app() 8 | } 9 | \value{ 10 | a shiny app 11 | } 12 | \description{ 13 | Launch Reactor Data Shiny App 14 | } 15 | -------------------------------------------------------------------------------- /R/launch_app.R: -------------------------------------------------------------------------------- 1 | #' Launch Reactor Data Shiny App 2 | #' 3 | #' @return a shiny app 4 | #' @export 5 | launch_app = function(){ 6 | check_package("shiny") 7 | app = system.file( 8 | "shiny", 9 | "shinyApp.R", 10 | package = "ggVennDiagram", 11 | mustWork = TRUE 12 | ) 13 | if(interactive()) shiny::runApp(app) 14 | } 15 | -------------------------------------------------------------------------------- /man/get_shapes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_shape.R 3 | \name{get_shapes} 4 | \alias{get_shapes} 5 | \title{Get all shapes} 6 | \usage{ 7 | get_shapes() 8 | } 9 | \value{ 10 | a tibble 11 | } 12 | \description{ 13 | Get all shapes 14 | } 15 | \examples{ 16 | get_shapes() 17 | } 18 | -------------------------------------------------------------------------------- /tests/testthat/test-class-Venn.R: -------------------------------------------------------------------------------- 1 | test_that("Venn methods work", { 2 | sets <- list(A=1:5,B=3:9,C=c(1,3,5,7,9,11)) 3 | sets <- lapply(sets, as.character) 4 | venn <- Venn(sets = sets) 5 | 6 | expect_equal(discern_overlap(venn), c("3","5")) 7 | expect_equal(discern_overlap(venn,1:2), c("4")) 8 | expect_equal(overlap(venn), c("3","5")) 9 | }) 10 | -------------------------------------------------------------------------------- /man/combinations.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/regions.R 3 | \name{combinations} 4 | \alias{combinations} 5 | \title{all possible combinations of n sets} 6 | \usage{ 7 | combinations(n) 8 | } 9 | \arguments{ 10 | \item{n}{dim} 11 | } 12 | \description{ 13 | all possible combinations of n sets 14 | } 15 | -------------------------------------------------------------------------------- /R/check_pakage.R: -------------------------------------------------------------------------------- 1 | check_package = function(package = "ggVennDiagram"){ 2 | if (!requireNamespace(package, quietly = TRUE)){ 3 | stop(paste("The", package, "package is not found in your library paths.", 4 | " It is required to show intersections interactively.", 5 | " Please run `install.packages('package')` and retry.", 6 | collapse = "\n")) 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /man/all_identical.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/classVenn.R 3 | \name{all_identical} 4 | \alias{all_identical} 5 | \title{All members of a list have the same elements} 6 | \usage{ 7 | all_identical(list) 8 | } 9 | \arguments{ 10 | \item{list}{a list} 11 | } 12 | \value{ 13 | TRUE or FALSE 14 | } 15 | \description{ 16 | All members of a list have the same elements 17 | } 18 | -------------------------------------------------------------------------------- /man/get_shape_by_id.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_shape.R 3 | \name{get_shape_by_id} 4 | \alias{get_shape_by_id} 5 | \title{Specifying a shape} 6 | \usage{ 7 | get_shape_by_id(id) 8 | } 9 | \arguments{ 10 | \item{id}{shape id} 11 | } 12 | \value{ 13 | a shape 14 | } 15 | \description{ 16 | Specifying a shape 17 | } 18 | \examples{ 19 | get_shape_by_id("401f") 20 | } 21 | -------------------------------------------------------------------------------- /man/slice_idx.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setOperations.R 3 | \name{slice_idx} 4 | \alias{slice_idx} 5 | \title{check and format slice name} 6 | \usage{ 7 | slice_idx(venn, slice) 8 | } 9 | \arguments{ 10 | \item{venn}{a Venn object} 11 | 12 | \item{slice}{a numeric or character vector} 13 | } 14 | \value{ 15 | the index of Venn (numeric vector) or "all" 16 | } 17 | \description{ 18 | check and format slice name 19 | } 20 | -------------------------------------------------------------------------------- /ggVennDiagram.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Yes 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /man/plotData_add_venn.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/process_data.R 3 | \name{plotData_add_venn} 4 | \alias{plotData_add_venn} 5 | \title{join the shape data with set data} 6 | \usage{ 7 | plotData_add_venn(plotData, venn) 8 | } 9 | \arguments{ 10 | \item{plotData}{a VennPlot object that stores plot shapes} 11 | 12 | \item{venn}{a Venn object that stores set values} 13 | } 14 | \description{ 15 | join the shape data with set data 16 | } 17 | -------------------------------------------------------------------------------- /tests/testthat/test-memory_usage.R: -------------------------------------------------------------------------------- 1 | test_that("memory usage for large list", { 2 | 3 | large_list <- list(Score = as.character(rnorm(130000, 80, 20)), 4 | Length = as.character(rnorm(6000, 200, 50)), 5 | Charge = as.character(rnorm(90000, 2000, 800)), 6 | Math = as.character(rnorm(100000,90,20)), 7 | Total = as.character(rnorm(10000,100,30))) 8 | expect_s3_class(ggVennDiagram(large_list), "ggplot") 9 | }) 10 | -------------------------------------------------------------------------------- /man/plot_shape_edge.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_shapes.R 3 | \name{plot_shape_edge} 4 | \alias{plot_shape_edge} 5 | \title{Plot the set edge of a VennPlotData} 6 | \usage{ 7 | plot_shape_edge(x) 8 | } 9 | \arguments{ 10 | \item{x}{a VennPlotData object} 11 | } 12 | \value{ 13 | a ggplot object 14 | } 15 | \description{ 16 | This is for viewing the shape id and appearance of the shape. 17 | } 18 | \examples{ 19 | shape = get_shape_by_id("301") 20 | plot_shape_edge(shape) 21 | } 22 | -------------------------------------------------------------------------------- /man/separate_longer_delim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/upset_plot.R 3 | \name{separate_longer_delim} 4 | \alias{separate_longer_delim} 5 | \title{Implement of \code{tidyr::separate_longer_delim}} 6 | \usage{ 7 | separate_longer_delim(df, col, delim) 8 | } 9 | \arguments{ 10 | \item{df}{a data.frame} 11 | 12 | \item{col}{column} 13 | 14 | \item{delim}{delimeter} 15 | } 16 | \value{ 17 | a data.frame 18 | } 19 | \description{ 20 | Implement of \code{tidyr::separate_longer_delim} 21 | } 22 | -------------------------------------------------------------------------------- /man/print.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/upset_plot.R, R/view_shape.R 3 | \docType{methods} 4 | \name{print} 5 | \alias{print} 6 | \alias{print.upsetPlotData} 7 | \alias{print.VennPlotData} 8 | \title{S3 method for \code{upsetPlotData}} 9 | \usage{ 10 | \method{print}{upsetPlotData}(x, ...) 11 | 12 | \method{print}{VennPlotData}(x, ...) 13 | } 14 | \arguments{ 15 | \item{x}{a VennPlotData object} 16 | 17 | \item{...}{useless} 18 | } 19 | \description{ 20 | S3 method for \code{upsetPlotData} 21 | 22 | S3 method for \code{VennPlotData} 23 | } 24 | -------------------------------------------------------------------------------- /inst/shiny/www/shinyApp.css: -------------------------------------------------------------------------------- 1 | .form-control input { 2 | padding: 0rem; 3 | } 4 | 5 | .form-control .control-label { 6 | display: none; 7 | } 8 | 9 | .form-group { 10 | margin-top: 0.3rem; 11 | margin-bottom: 0.3rem; 12 | } 13 | 14 | .shiny-input-text, .shiny-input-textarea { 15 | border-color: whitesmoke; 16 | padding: 0.1rem; 17 | } 18 | 19 | .shiny-input-text { 20 | font-weight: bold; 21 | } 22 | 23 | /* move button to right */ 24 | 25 | 26 | .action-button { 27 | float: right; 28 | margin-top: 1rem; 29 | } 30 | /* move button to right */ 31 | 32 | 33 | 34 | div.inline { 35 | display: flex; 36 | } 37 | -------------------------------------------------------------------------------- /tests/testthat/test-upset.R: -------------------------------------------------------------------------------- 1 | test_that("upset plot works", { 2 | list = list(A = LETTERS[1:10], 3 | B = LETTERS[8:15], 4 | C = LETTERS[10:13]) 5 | venn = Venn(list) 6 | data = process_upset_data(venn, 7 | order.intersect.by = "size", 8 | order.set.by = "name") 9 | expect_equal(data$top_data$name, c("A","B","C","A/B","A/C","B/C","A/B/C")) 10 | expect_equal(data$top_data$size, c(7L,2L,0L,2L,0L,3L,1L)) 11 | expect_equal(data$top_data$item[[1]], LETTERS[1:7]) 12 | p = plot_upset(venn, order.intersect.by = "name") 13 | expect_s3_class(p, c("upset_plot","aplot")) 14 | }) 15 | -------------------------------------------------------------------------------- /man/get_shape_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_shape.R 3 | \name{get_shape_data} 4 | \alias{get_shape_data} 5 | \title{get applicable shape data for Venn object} 6 | \usage{ 7 | get_shape_data(nsets, type = NULL, shape_id = NULL) 8 | } 9 | \arguments{ 10 | \item{nsets}{number of sets} 11 | 12 | \item{type}{type of shape} 13 | 14 | \item{shape_id}{shape id} 15 | } 16 | \value{ 17 | a tibble describing specific shape 18 | } 19 | \description{ 20 | ggVennDiagram stores shapes as internal data. You may see all the shapes by 21 | using `plot_shapes()` or `get_shapes()`. 22 | } 23 | \examples{ 24 | get_shape_data(nsets = 4, type = "polygon") 25 | } 26 | -------------------------------------------------------------------------------- /man/plot_shapes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_shapes.R 3 | \name{plot_shapes} 4 | \alias{plot_shapes} 5 | \title{plot all shapes provided by internal dataset} 6 | \usage{ 7 | plot_shapes() 8 | } 9 | \description{ 10 | These shapes are mainly collected from the package \code{venn}, and \code{VennDiagram}. 11 | For Venn plot with more than 4 sets, it is usually impossible to plot with 12 | simple circle or ellipse. So we need to use a predefined coordinates in plot. 13 | } 14 | \details{ 15 | \itemize{ 16 | \item Shape 101, 201, 301, 401, 402, 501, 502, 601 and 701 are from \code{venn} 17 | \item Shape 401f is from \code{VennDiagram} 18 | } 19 | 20 | see \code{data-raw/shapes.R} to find how we incorporate these data. 21 | } 22 | \examples{ 23 | plot_shapes() 24 | } 25 | -------------------------------------------------------------------------------- /man/shapes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_shapes.R 3 | \docType{data} 4 | \name{shapes} 5 | \alias{shapes} 6 | \title{shapes: shape data used to setup Venn plot} 7 | \format{ 8 | a list with several slots 9 | see "?VennPlotData". 10 | } 11 | \source{ 12 | \itemize{ 13 | \item The \code{venn} datasets authored by Adrian Dusa (\url{https://CRAN.R-project.org/package=venn}). 14 | \item Parameters used to generate fancy four set ellipses are adopted from \code{VennDiagram}(\url{https://CRAN.R-project.org/package=VennDiagram}). 15 | \item \href{https://upload.wikimedia.org/wikipedia/commons/5/56/6-set_Venn_diagram_SMIL.svg}{Wiki} 16 | } 17 | } 18 | \description{ 19 | a collection of geometric shapes, which defined the edge and label of sets in a Venn plot. 20 | use \code{plot_shapes()} to see some of them. 21 | } 22 | -------------------------------------------------------------------------------- /man/unite.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setOperations.R 3 | \name{unite} 4 | \alias{unite} 5 | \alias{unite,Venn-method} 6 | \title{Union of many sets.} 7 | \usage{ 8 | unite(venn, slice = "all") 9 | 10 | \S4method{unite}{Venn}(venn, slice = "all") 11 | } 12 | \arguments{ 13 | \item{venn}{(Required) A \code{Venn} object.} 14 | 15 | \item{slice}{(Optional) The names or the indices of sets of interest. Default 16 | is "all", meaning the union will be calculated for all the sets.} 17 | } 18 | \value{ 19 | A vector showing the union of the sets. 20 | } 21 | \description{ 22 | \code{unite} returns the union of the sets in a \code{Venn} object. 23 | } 24 | \examples{ 25 | venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) 26 | unite(venn) 27 | unite(venn, slice = c(1, 2)) 28 | } 29 | \author{ 30 | tyakyol@gmail.com 31 | } 32 | -------------------------------------------------------------------------------- /man/overlap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setOperations.R 3 | \name{overlap} 4 | \alias{overlap} 5 | \alias{overlap,Venn-method} 6 | \title{Intersection of many sets.} 7 | \usage{ 8 | overlap(venn, slice = "all") 9 | 10 | \S4method{overlap}{Venn}(venn, slice = "all") 11 | } 12 | \arguments{ 13 | \item{venn}{(Required) A \code{Venn} object.} 14 | 15 | \item{slice}{(Optional) The names or the indices of sets of interest. Default 16 | is "all", meaning the intersection will be calculated for all the sets.} 17 | } 18 | \value{ 19 | A vector showing the intersection of the sets. 20 | } 21 | \description{ 22 | \code{overlap} returns the same elements of the sets in a \code{Venn} object. 23 | } 24 | \examples{ 25 | venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) 26 | overlap(venn) 27 | overlap(venn, slice = c(1, 2)) 28 | } 29 | \author{ 30 | tyakyol@gmail.com 31 | } 32 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ # Designates the directory as an RStudio Project 2 | ^\.Rproj\.user$ # Used by RStudio for temporary files 3 | ^README\.Rmd$ # An Rmd file used to generate README.md 4 | ^LICENSE\.md$ # Full text of the license 5 | ^cran-comments\.md$ # Comments for CRAN submission 6 | ^\.travis\.yml$ # Used by Travis-CI for continuous integration testing 7 | ^data-raw$ # Code used to create data included in the package 8 | ^pkgdown$ # Resources used for the package website 9 | ^_pkgdown\.yml$ # Configuration info for the package website 10 | ^\.github$ # Contributing guidelines, CoC, issue templates, etc. 11 | ^LICENSE\.md$ 12 | ^README\.rmd$ 13 | ^ggVennDiagram\.Rproj$ 14 | ^cran-comments\.md$ 15 | ^CRAN-RELEASE$ 16 | ^data-raw$ 17 | ^.travis.yml$ 18 | ^\.github$ 19 | ^_pkgdown\.yml$ 20 | ^doc$ 21 | ^Meta$ 22 | ^vignettes/using-ggVennDiagram-cn\.Rmd$ 23 | ^CRAN-SUBMISSION$ 24 | ^less-dependency.Rmd$ 25 | ^docs$ 26 | ^roadmap\.md$ 27 | ^pkgdown$ 28 | ^inst/cli$ 29 | -------------------------------------------------------------------------------- /R/regions.R: -------------------------------------------------------------------------------- 1 | # region items and polygons 2 | 3 | #' all possible combinations of n sets 4 | #' 5 | #' @param n dim 6 | #' 7 | #' @importFrom utils combn 8 | combinations <- function(n){ 9 | l <- lapply(seq_len(n), function(x){ 10 | m <- combn(n,x) 11 | matrix2list(m) 12 | }) 13 | unlist(l, recursive = F) 14 | } 15 | 16 | matrix2list <- function(matrix){ 17 | lapply(seq_len(ncol(matrix)), function(i) matrix[,i]) 18 | } 19 | 20 | get_subset_items <- function(venn, specific = TRUE){ 21 | n = length(venn@sets) 22 | c = combinations(n) 23 | fun = ifelse(specific, "discern_overlap", "overlap") 24 | lapply(c, fun, venn = venn) 25 | } 26 | 27 | get_subset_names <- function(venn, sep = "/"){ 28 | n = length(venn@sets) 29 | set_name = venn@names 30 | c = combinations(n) 31 | sapply(c, function(i) paste0(set_name[i], collapse = sep)) 32 | } 33 | 34 | get_subset_ids <- function(venn, sep = "/"){ 35 | n = length(venn@sets) 36 | c = combinations(n) 37 | sapply(c, function(i) paste0(i, collapse = sep)) 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /man/discern_overlap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setOperations.R 3 | \name{discern_overlap} 4 | \alias{discern_overlap} 5 | \alias{discern_overlap,Venn-method} 6 | \title{Calculate region of sets} 7 | \usage{ 8 | discern_overlap(venn, slice = "all") 9 | 10 | \S4method{discern_overlap}{Venn}(venn, slice = "all") 11 | } 12 | \arguments{ 13 | \item{venn}{a Venn object} 14 | 15 | \item{slice}{index of Venn members, default is "all"} 16 | } 17 | \value{ 18 | region items 19 | } 20 | \description{ 21 | calculate the unique region defined 22 | by `Venn` object and the parameter `slice`. 23 | } 24 | \examples{ 25 | library(ggVennDiagram) 26 | venn <- Venn(list(A=1:3,B=2:5,C=c(1L,3L,5L))) 27 | 28 | discern_overlap(venn, slice = "all") 29 | # is equal to 30 | overlap(venn, slice = "all") 31 | 32 | # however, `discern_overlap()` only contains specific region 33 | discern_overlap(venn, slice = 1:2) 34 | # is different from 35 | overlap(venn, slice = 1:2) 36 | } 37 | \author{ 38 | gaospecial@gmail.com 39 | } 40 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(print,VennPlotData) 4 | S3method(print,upsetPlotData) 5 | export(Venn) 6 | export(discern_overlap) 7 | export(get_shape_by_id) 8 | export(get_shape_data) 9 | export(get_shapes) 10 | export(ggVennDiagram) 11 | export(launch_app) 12 | export(plotData_add_venn) 13 | export(plot_shape_edge) 14 | export(plot_shapes) 15 | export(plot_upset) 16 | export(plot_venn) 17 | export(process_data) 18 | export(process_region_data) 19 | export(process_set_data) 20 | export(venn_region) 21 | export(venn_regionedge) 22 | export(venn_regionlabel) 23 | export(venn_set) 24 | export(venn_setedge) 25 | export(venn_setlabel) 26 | exportMethods(Venn) 27 | exportMethods(discern) 28 | exportMethods(discern_overlap) 29 | exportMethods(overlap) 30 | exportMethods(process_data) 31 | exportMethods(show) 32 | exportMethods(unite) 33 | import(ggplot2) 34 | importFrom(graphics,par) 35 | importFrom(methods,new) 36 | importFrom(methods,show) 37 | importFrom(methods,slot) 38 | importFrom(methods,slotNames) 39 | importFrom(utils,combn) 40 | -------------------------------------------------------------------------------- /man/venn_plot_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/process_data.R 3 | \name{venn_plot_data} 4 | \alias{venn_plot_data} 5 | \alias{venn_regionedge} 6 | \alias{venn_regionlabel} 7 | \alias{venn_setedge} 8 | \alias{venn_setlabel} 9 | \alias{venn_set} 10 | \alias{venn_region} 11 | \title{Get VennPlotData slot} 12 | \usage{ 13 | venn_regionedge(obj) 14 | 15 | venn_regionlabel(obj) 16 | 17 | venn_setedge(obj) 18 | 19 | venn_setlabel(obj) 20 | 21 | venn_set(obj) 22 | 23 | venn_region(obj) 24 | } 25 | \arguments{ 26 | \item{obj}{a list that stores all the data from the S3 class `VennPlotData` object} 27 | } 28 | \value{ 29 | a tibble 30 | } 31 | \description{ 32 | Get VennPlotData slot 33 | } 34 | \examples{ 35 | venn = Venn(list(A=1:5,B=2:7,C=3:6,D=4:9)) 36 | obj = process_data(venn) 37 | venn_regionlabel(obj) # return regionLabel data 38 | venn_regionedge(obj) # return regionEdge data 39 | venn_setlabel(obj) # return setLabel data 40 | venn_setedge(obj) # return setEdge data 41 | venn_set(obj) # set items 42 | venn_region(obj) # region items 43 | } 44 | -------------------------------------------------------------------------------- /man/process_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/process_data.R 3 | \docType{methods} 4 | \name{process_data} 5 | \alias{process_data} 6 | \alias{process_data,Venn-method} 7 | \title{get plot data} 8 | \usage{ 9 | process_data(venn, nsets = NULL, shape_id = NULL, type = NULL) 10 | 11 | \S4method{process_data}{Venn}(venn, nsets = length(venn@sets), shape_id = NULL, type = NULL) 12 | } 13 | \arguments{ 14 | \item{venn}{a Venn object} 15 | 16 | \item{nsets}{This parameter will be set automatically.} 17 | 18 | \item{shape_id}{apply filter to internal shapes. i.e. shape_id = "601"} 19 | 20 | \item{type}{apply filter to internal shapes. i.e. type = "polygon"} 21 | } 22 | \description{ 23 | get plot data 24 | } 25 | \details{ 26 | This function will conduct set operations and combine the outputs will 27 | stored shapes, thus produce a dataset for plot in next step. 28 | 29 | Run `get_shapes()` to show all the characteristics of available shapes. 30 | Run `plot_shapes()` to view those shapes. 31 | } 32 | \examples{ 33 | \dontrun{ 34 | venn = Venn(list(A=1:3,B=2:5,C=4:8)) 35 | data = process_data(venn) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /man/discern.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setOperations.R 3 | \name{discern} 4 | \alias{discern} 5 | \alias{discern,Venn-method} 6 | \title{Set difference.} 7 | \usage{ 8 | discern(venn, slice1, slice2 = "all") 9 | 10 | \S4method{discern}{Venn}(venn, slice1, slice2 = "all") 11 | } 12 | \arguments{ 13 | \item{venn}{(Required) A \code{Venn} object.} 14 | 15 | \item{slice1}{(Required) The name or the index of the set of interest. 16 | Multiple sets can be selected.} 17 | 18 | \item{slice2}{(Optional) The name or the index of the set of interest. 19 | Multiple sets can be selected. Default is all the sets except the sets of 20 | slice1.} 21 | } 22 | \value{ 23 | A vector showing the difference between slice1 and slice2. 24 | } 25 | \description{ 26 | \code{discern} returns the difference between two group of sets selected from 27 | a \code{Venn} object. If multiple sets are chosen for the slices, union of 28 | those sets will be used. 29 | } 30 | \examples{ 31 | venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) 32 | discern(venn, slice1 = 1) 33 | discern(venn, slice1 = c(1, 2), slice2 = 3) 34 | } 35 | \author{ 36 | tyakyol@gmail.com 37 | } 38 | -------------------------------------------------------------------------------- /man/process_upset_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/upset_plot.R 3 | \name{process_upset_data} 4 | \alias{process_upset_data} 5 | \title{process upset data} 6 | \usage{ 7 | process_upset_data( 8 | venn, 9 | nintersects = 30, 10 | order.intersect.by = "size", 11 | order.set.by = "name", 12 | specific = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{venn}{a class Venn object} 17 | 18 | \item{nintersects}{number of intersects. If NULL, all intersections will show.} 19 | 20 | \item{order.intersect.by}{'size', 'name', or "none"} 21 | 22 | \item{order.set.by}{'size', 'name', or "none"} 23 | 24 | \item{specific}{whether return ONLY specific items for a subset, default is TRUE} 25 | } 26 | \value{ 27 | a upsetPlotData object 28 | } 29 | \description{ 30 | process upset data 31 | } 32 | \details{ 33 | ggVennDiagram, by default, only return the specific subsets of a region. 34 | However, sometimes, we want to show all the overlapping items for two or more sets. 35 | For example: https://github.com/gaospecial/ggVennDiagram/issues/64 36 | Therefore, we add a 'specific' switch to this function. While 'specific = FALSE', 37 | the seperator will be changed from "/" to "~", and all the overlapping items 38 | will be returned. This feature is useful in plotting upset plot. 39 | } 40 | -------------------------------------------------------------------------------- /man/Venn-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/classVenn.R 3 | \docType{class} 4 | \name{Venn-class} 5 | \alias{Venn-class} 6 | \alias{Venn} 7 | \alias{Venn,ANY-method} 8 | \alias{show,Venn-method} 9 | \title{\emph{\code{Venn}} is a S4 class to represent multiple sets.} 10 | \usage{ 11 | Venn(sets, names = NULL) 12 | 13 | \S4method{Venn}{ANY}(sets, names = NULL) 14 | 15 | \S4method{show}{Venn}(object) 16 | } 17 | \arguments{ 18 | \item{sets}{(Required) A list containing vectors in the same class. If a 19 | vector contains duplicates they will be discarded. If the list doesn't have 20 | names the sets will be named as "Set_1", "Set_2", "Set_3" and so on.} 21 | 22 | \item{names}{names of sets} 23 | 24 | \item{object}{a Venn class object} 25 | } 26 | \value{ 27 | A \code{Venn} object. 28 | } 29 | \description{ 30 | Print user-friendly information of a Venn object 31 | } 32 | \section{Slots}{ 33 | 34 | \describe{ 35 | \item{\code{sets}}{A \code{list} object containing vectors in the same type.} 36 | 37 | \item{\code{names}}{The names of the \code{sets} if it has names. If the \code{list} 38 | doesn't have names, the sets will be named as "Set_1", "Set_2", "Set_3" and 39 | so on.} 40 | }} 41 | 42 | \examples{ 43 | venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) 44 | print(venn) 45 | } 46 | -------------------------------------------------------------------------------- /man/venn_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/process_data.R 3 | \name{venn_data} 4 | \alias{venn_data} 5 | \alias{process_set_data} 6 | \alias{process_region_data} 7 | \title{Prepare Venn data} 8 | \usage{ 9 | process_set_data(venn) 10 | 11 | process_region_data(venn, sep = "/", specific = TRUE) 12 | } 13 | \arguments{ 14 | \item{venn}{a Venn object} 15 | 16 | \item{sep}{name and id separator for intersections} 17 | 18 | \item{specific}{whether return ONLY specific items for a subset, default is TRUE} 19 | } 20 | \value{ 21 | a tibble 22 | } 23 | \description{ 24 | Prepare Venn data 25 | } 26 | \details{ 27 | ggVennDiagram, by default, only return the specific subsets of a region. 28 | However, sometimes, we want to show all the overlapping items for two or more sets. 29 | For example: https://github.com/gaospecial/ggVennDiagram/issues/64 30 | Therefore, we add a 'specific' switch to this function. While 'specific = FALSE', 31 | the seperator will be changed from "/" to "~", and all the overlapping items 32 | will be returned. This feature is useful in plotting upset plot. 33 | } 34 | \examples{ 35 | x = list( 36 | A = sample(letters, 8), 37 | B = sample(letters, 8), 38 | C = sample(letters, 8), 39 | D = sample(letters, 8) 40 | ) 41 | 42 | venn = Venn(x) 43 | process_set_data(venn) 44 | process_region_data(venn) 45 | } 46 | -------------------------------------------------------------------------------- /man/VennPlotData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/view_shape.R 3 | \name{VennPlotData} 4 | \alias{VennPlotData} 5 | \title{An S3 class constructor of representing Venn plot components.} 6 | \usage{ 7 | VennPlotData(x) 8 | } 9 | \arguments{ 10 | \item{x}{data source of a VennPlotData object} 11 | } 12 | \description{ 13 | An S3 class constructor of representing Venn plot components. 14 | } 15 | \section{Slots}{ 16 | 17 | \describe{ 18 | \item{\code{shapeId}}{shape id} 19 | 20 | \item{\code{type}}{type of shape} 21 | 22 | \item{\code{nsets}}{number of sets} 23 | 24 | \item{\code{setEdge}}{a data.frame, the coordinates of set edges, can be retrieved by \code{venn_setedge()}} 25 | 26 | \item{\code{setLabel}}{a data.frame, the coordinates of set labels, can be retrieved by \code{venn_setlabel()}} 27 | 28 | \item{\code{regionEdge}}{a data.frame, the coordinates of different regions, can be retrieved by \code{venn_regionedge()}} 29 | 30 | \item{\code{regionLabel}}{a data.frame, the centroid of the regions, where region labels anchored, can be retrieved by \code{venn_regionlabel()}} 31 | 32 | \item{\code{setData}}{a data.frame, the set data provided by user, can be retrieved by \code{venn_set()}} 33 | 34 | \item{\code{regionData}}{a data.frame, the region data that calculated by \code{ggVennDiagram}, can be retrieved by \code{venn_region()}} 35 | }} 36 | 37 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://gaospecial.github.io/ggVennDiagram/ 2 | home: 3 | strip_header: yes 4 | reference: 5 | - title: Main wrapers 6 | desc: Main functions of 'ggVennDiagram' 7 | contents: 8 | - ggVennDiagram 9 | - plot_venn 10 | - plot_upset 11 | - title: Shape viewer 12 | desc: methods used to get and view shape data 13 | contents: 14 | - plot_shapes 15 | - plot_shape_edge 16 | - get_shapes 17 | - get_shape_data 18 | - get_shape_by_id 19 | - shapes 20 | - vensets 21 | - title: VennPlotData object and methods 22 | desc: a S3 class to store Venn sets and shape data 23 | contents: 24 | - process_data 25 | - plotData_add_venn 26 | - VennPlotData 27 | - venn_plot_data 28 | - print 29 | - title: Venn object and methods 30 | desc: a S4 class to store Venn sets and calculate subsets 31 | contents: 32 | - Venn-class 33 | - venn_data 34 | - venn_region 35 | - venn_regionedge 36 | - venn_regionlabel 37 | - venn_set 38 | - venn_setedge 39 | - venn_setlabel 40 | - title: subset processing 41 | desc: helper functions to calculate subset members 42 | contents: 43 | - combinations 44 | - all_identical 45 | - discern_overlap 46 | - discern 47 | - overlap 48 | - unite 49 | - slice_idx 50 | - title: Upset plot utility 51 | desc: helper function for upset plot 52 | contents: 53 | - process_upset_data 54 | - separate_longer_delim 55 | - title: Shiny app 56 | desc: run a Shiny app to plot 57 | contents: 58 | - launch_app 59 | -------------------------------------------------------------------------------- /roadmap.md: -------------------------------------------------------------------------------- 1 | # The future of ggVennDiagram development 2 | 3 | - [x] less dependency 4 | - [ ] class methods 5 | - [ ] support of upset plot, and more... 6 | - [ ] add additional upset plot parameters into `ggVennDiagram()` 7 | - [ ] add a independent Upset plot function `ggUpset()` 8 | - [ ] sort set name/set intersection more reasonably 9 | - [ ] more types of upset plot 10 | - [ ] `upset_boxplot` 11 | - [ ] `upset_dotplot`. 12 | - [ ] a shiny app 13 | - [ ] disable auto update of plot (only plot after clicking Plot button) 14 | - [ ] more parameters in tab 15 | - [ ] export figure as PPTX 16 | - [ ] a TBtools plugin 17 | - [ ] unified scale of shapes (from 0 to 1) 18 | - [ ] cartoon style 19 | 20 | ## Comment by ChatGPT 21 | 22 | 你的ggVennDiagram未来的开发计划看起来很全面,考虑到了多个方面的增强和改进。以下是对计划中一些建议的一些建议: 23 | 24 | 1. **Less Dependency:** 25 | - 减少依赖是一个很好的目标,可以提高包的可用性和可维护性。确保在减少依赖的同时,仍然能够提供充分的功能。 26 | 27 | 2. **Support of Upset Plot:** 28 | - Upset plot 的支持是一个重要的增强,可以使 ggVennDiagram 更加全面。确保在添加新功能时保持代码清晰和易于理解。 29 | 30 | 3. **Shiny App:** 31 | - Shiny app 的添加是一个很好的功能,可以提供更直观的交互性。确保在增加更多参数和功能时保持用户友好性。 32 | 33 | 4. **TBtools Plugin:** 34 | - TBtools plugin 的整合是一个很好的创意,可以使得工具在更广泛的生物信息学环境中得到应用。确保插件的集成是平滑的,用户能够轻松地与 TBtools 进行交互。 35 | 36 | 5. **Unified Scale of Shapes:** 37 | - 统一形状的比例是一个良好的设计选择,可以提高图形的一致性。确保在调整比例时考虑到用户的习惯和期望。 38 | 39 | 6. **Cartoon Style:** 40 | - 卡通风格的添加是一个有趣的想法,可以使图形更有趣。确保在实施时提供足够的自定义选项,以适应用户的各种设计偏好。 41 | 42 | 最重要的是,持续的开发和关注用户反馈将有助于确保 ggVennDiagram 成为一个强大而受欢迎的工具。祝你的开发计划取得成功! 43 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | release: 9 | types: [published] 10 | workflow_dispatch: 11 | 12 | name: pkgdown 13 | 14 | jobs: 15 | pkgdown: 16 | runs-on: ubuntu-latest 17 | # Only restrict concurrency for non-PR jobs 18 | concurrency: 19 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 20 | env: 21 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 22 | permissions: 23 | contents: write 24 | steps: 25 | - uses: actions/checkout@v3 26 | 27 | - uses: r-lib/actions/setup-pandoc@v2 28 | 29 | - uses: r-lib/actions/setup-r@v2 30 | with: 31 | use-public-rspm: true 32 | 33 | - uses: r-lib/actions/setup-r-dependencies@v2 34 | with: 35 | extra-packages: any::pkgdown, local::., badger 36 | needs: website 37 | 38 | - name: Build site 39 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 40 | shell: Rscript {0} 41 | 42 | - name: Deploy to GitHub pages 🚀 43 | if: github.event_name != 'pull_request' 44 | uses: JamesIves/github-pages-deploy-action@v4.4.1 45 | with: 46 | clean: false 47 | branch: gh-pages 48 | folder: docs 49 | -------------------------------------------------------------------------------- /R/view_shape.R: -------------------------------------------------------------------------------- 1 | #' An S3 class constructor of representing Venn plot components. 2 | #' 3 | #' @param x data source of a VennPlotData object 4 | #' 5 | #' @slot shapeId shape id 6 | #' @slot type type of shape 7 | #' @slot nsets number of sets 8 | #' @slot setEdge a data.frame, the coordinates of set edges, can be retrieved by `venn_setedge()` 9 | #' @slot setLabel a data.frame, the coordinates of set labels, can be retrieved by `venn_setlabel()` 10 | #' @slot regionEdge a data.frame, the coordinates of different regions, can be retrieved by `venn_regionedge()` 11 | #' @slot regionLabel a data.frame, the centroid of the regions, where region labels anchored, can be retrieved by `venn_regionlabel()` 12 | #' @slot setData a data.frame, the set data provided by user, can be retrieved by `venn_set()` 13 | #' @slot regionData a data.frame, the region data that calculated by `ggVennDiagram`, can be retrieved by `venn_region()` 14 | #' @md 15 | VennPlotData = function(x){ 16 | class(x) = "VennPlotData" 17 | return(x) 18 | } 19 | 20 | #' S3 method for `VennPlotData` 21 | #' 22 | #' @param x a VennPlotData object 23 | #' @param ... useless 24 | #' 25 | #' @method print VennPlotData 26 | #' @docType methods 27 | #' @rdname print 28 | #' @name print 29 | #' @md 30 | #' @export 31 | print.VennPlotData = function(x, ...){ 32 | cat(sprintf("Class VennPlotData - '%s'\n", x$shapeId)) 33 | cat(sprintf(" Type: %s; No. sets: %d; No. regions: %d.\n", x$type, x$nsets, length(unique(x$regionEdge$id)))) 34 | cat(sprintf(" To view this shape, use `plot_shape_edge(get_shape_by_id('%s'))`.\n", x$shapeId)) 35 | cat(sprintf(" To view its components, use `venn_setedge()`, `venn_setlabel()`, etc.\n")) 36 | } 37 | 38 | -------------------------------------------------------------------------------- /man/plot_venn.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggVennDiagram.R 3 | \name{plot_venn} 4 | \alias{plot_venn} 5 | \title{plot codes} 6 | \usage{ 7 | plot_venn( 8 | data, 9 | show_intersect = FALSE, 10 | set_color = "black", 11 | set_size = NA, 12 | label = "both", 13 | label_geom = "label", 14 | label_alpha = 0.5, 15 | label_font = "sans", 16 | label_color = "black", 17 | label_size = NA, 18 | label_percent_digit = 0, 19 | label_bigMark = ",", 20 | label_bigInterval = 3L, 21 | label_txtWidth = 40, 22 | edge_lty = "solid", 23 | edge_size = 1, 24 | ... 25 | ) 26 | } 27 | \arguments{ 28 | \item{data}{plot data} 29 | 30 | \item{show_intersect}{if TRUE the text can be visualized by `plotly`} 31 | 32 | \item{set_color}{color of set labels ("black")} 33 | 34 | \item{set_size}{size of set labels (NA)} 35 | 36 | \item{label}{format of region labels, select one from c("count","percent","both","none")} 37 | 38 | \item{label_geom}{layer of region labels, choose from c("label", "text")} 39 | 40 | \item{label_alpha}{set 0 to remove the background of region labels} 41 | 42 | \item{label_font}{font name of labels} 43 | 44 | \item{label_color}{color of region labels ("black")} 45 | 46 | \item{label_size}{size of region labels (NA)} 47 | 48 | \item{label_percent_digit}{number of digits when formatting percent label (0)} 49 | 50 | \item{label_bigMark}{Type of thousand separator} 51 | 52 | \item{label_bigInterval}{Position of thousand separator} 53 | 54 | \item{label_txtWidth}{width of text used in showing intersect members, will be ignored unless show_intersection is TRUE (40)} 55 | 56 | \item{edge_lty}{line type of set edges ("solid")} 57 | 58 | \item{edge_size}{line width of set edges (1)} 59 | 60 | \item{...}{useless} 61 | } 62 | \value{ 63 | ggplot object, or plotly object if show_intersect is TRUE 64 | } 65 | \description{ 66 | plot codes 67 | } 68 | -------------------------------------------------------------------------------- /R/plot_shapes.R: -------------------------------------------------------------------------------- 1 | #' shapes: shape data used to setup Venn plot 2 | #' 3 | #' a collection of geometric shapes, which defined the edge and label of sets in a Venn plot. 4 | #' use `plot_shapes()` to see some of them. 5 | #' 6 | #' @format a list with several slots 7 | #' see "?VennPlotData". 8 | #' 9 | #' @source 10 | #' - The `venn` datasets authored by Adrian Dusa (). 11 | #' 12 | #' - Parameters used to generate fancy four set ellipses are adopted from `VennDiagram`(). 13 | #' 14 | #' - [Wiki](https://upload.wikimedia.org/wikipedia/commons/5/56/6-set_Venn_diagram_SMIL.svg) 15 | #' @name shapes 16 | #' @docType data 17 | #' @md 18 | NULL 19 | 20 | #' plot all shapes provided by internal dataset 21 | #' 22 | #' These shapes are mainly collected from the package `venn`, and `VennDiagram`. 23 | #' For Venn plot with more than 4 sets, it is usually impossible to plot with 24 | #' simple circle or ellipse. So we need to use a predefined coordinates in plot. 25 | #' 26 | #' - Shape 101, 201, 301, 401, 402, 501, 502, 601 and 701 are from `venn` 27 | #' - Shape 401f is from `VennDiagram` 28 | #' 29 | #' see `data-raw/shapes.R` to find how we incorporate these data. 30 | #' 31 | #' 32 | #' @importFrom graphics par 33 | #' @import ggplot2 34 | #' @export 35 | #' @examples 36 | #' plot_shapes() 37 | #' @md 38 | plot_shapes <- function(){ 39 | plots = lapply(shapes, plot_shape_edge) 40 | aplot::plot_list(gglist = plots, widths = 1) 41 | } 42 | 43 | #' Plot the set edge of a VennPlotData 44 | #' 45 | #' This is for viewing the shape id and appearance of the shape. 46 | #' 47 | #' @param x a VennPlotData object 48 | #' 49 | #' @return a ggplot object 50 | #' @export 51 | #' 52 | #' @examples 53 | #' shape = get_shape_by_id("301") 54 | #' plot_shape_edge(shape) 55 | plot_shape_edge = function(x){ 56 | if (!inherits(x, "VennPlotData")) 57 | stop("Try to plot a non-VennPlotData object. Please check.") 58 | id = get_shape_id(x) 59 | edge = get_shape_setedge(x) 60 | ggplot2::ggplot(edge, aes(.data$X, .data$Y, group = id)) + 61 | ggplot2::geom_path() + 62 | ggplot2::coord_equal() + 63 | ggplot2::labs(title = id) + 64 | ggplot2::theme_void() + 65 | ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5)) 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: ggVennDiagram 2 | Type: Package 3 | Title: A 'ggplot2' Implement of Venn Diagram 4 | Version: 1.5.6 5 | Authors@R: c( 6 | person("Chun-Hui","Gao", email="gaospecial@gmail.com", role=c("aut","cre"), comment=c(ORCID = "0000-0002-1445-7939")), 7 | person("Guangchuang", "Yu", email = "guangchuangyu@gmail.com", role = c("ctb"), comment = c(ORCID = "0000-0002-6485-8781")), 8 | person("Adrian", "Dusa", email = "dusa.adrian@unibuc.ro", role = c("aut","cph"), 9 | comment = c(ORCID = "0000-0002-3525-9253", 10 | note = "Adrian Dusa is the author and copyright holder of venn, where ggVennDiagram imports the polygon coordinates enabling 5 - 7 sets Venn diagram.")), 11 | person("Turgut Yigit", "Akyol", email = "tyakyol@gmail.com", role = c("ctb"), comment=c(ORCID = "0000-0003-0897-7716")) 12 | ) 13 | Maintainer: Chun-Hui Gao 14 | Description: Easy-to-use functions to generate 2-7 sets Venn or upset plot in publication quality. 15 | 'ggVennDiagram' plot Venn or upset using well-defined geometry dataset and 'ggplot2'. The shapes of 2-4 sets 16 | Venn use circles and ellipses, while the shapes of 4-7 sets Venn use irregular polygons (4 has both forms), which 17 | are developed and imported from another package 'venn', authored by Adrian Dusa. We provided internal functions to 18 | integrate shape data with user provided sets data, and calculated the geometry of every regions/intersections 19 | of them, then separately plot Venn in four components, set edges/labels, and region edges/labels. 20 | From version 1.0, it is possible to customize these components as you demand in ordinary 'ggplot2' grammar. 21 | From version 1.4.4, it supports unlimited number of sets, as it can draw a plain upset plot automatically when 22 | number of sets is more than 7. 23 | Depends: 24 | R (>= 4.1.0) 25 | Imports: 26 | ggplot2 (>= 3.4.0), 27 | dplyr, 28 | methods, 29 | tibble, 30 | aplot, 31 | venn (>= 1.12), 32 | yulab.utils, 33 | forcats 34 | URL: https://github.com/gaospecial/ggVennDiagram, https://gaospecial.github.io/ggVennDiagram/ 35 | License: GPL-3 36 | Encoding: UTF-8 37 | RoxygenNote: 7.3.2 38 | Suggests: 39 | testthat (>= 2.1.0), 40 | knitr, 41 | plotly, 42 | RColorBrewer, 43 | shiny, 44 | rmarkdown, 45 | tidyr 46 | VignetteBuilder: knitr 47 | LazyData: true 48 | -------------------------------------------------------------------------------- /man/upset-plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/upset_plot.R 3 | \name{upset-plot} 4 | \alias{upset-plot} 5 | \alias{plot_upset} 6 | \title{Plot a upset plot} 7 | \usage{ 8 | plot_upset( 9 | venn, 10 | nintersects = NULL, 11 | order.intersect.by = c("size", "name", "none"), 12 | order.set.by = c("size", "name", "none"), 13 | relative_height = 3, 14 | relative_width = 0.3, 15 | top.bar.color = "grey30", 16 | top.bar.y.label = NULL, 17 | top.bar.show.numbers = TRUE, 18 | top.bar.numbers.size = 3, 19 | sets.bar.color = "grey30", 20 | sets.bar.show.numbers = FALSE, 21 | sets.bar.x.label = "Set Size", 22 | sets.bar.position = c("left", "right"), 23 | intersection.matrix.color = "grey30", 24 | specific = TRUE, 25 | ... 26 | ) 27 | } 28 | \arguments{ 29 | \item{venn}{a class Venn object} 30 | 31 | \item{nintersects}{number of intersects. If NULL, all intersections will show.} 32 | 33 | \item{order.intersect.by}{'size', 'name', or "none"} 34 | 35 | \item{order.set.by}{'size', 'name', or "none"} 36 | 37 | \item{relative_height}{the relative height of top panel in upset plot} 38 | 39 | \item{relative_width}{the relative width of left panel in upset plot} 40 | 41 | \item{top.bar.color}{default is "grey30"} 42 | 43 | \item{top.bar.y.label}{default is NULL} 44 | 45 | \item{top.bar.show.numbers}{default is TRUE} 46 | 47 | \item{top.bar.numbers.size}{text size of numbers} 48 | 49 | \item{sets.bar.color}{default is "grey30"} 50 | 51 | \item{sets.bar.show.numbers}{default is FALSE} 52 | 53 | \item{sets.bar.x.label}{default is "Set Size"} 54 | 55 | \item{sets.bar.position}{the bar plot position of sets ["left"]} 56 | 57 | \item{intersection.matrix.color}{default is "grey30"} 58 | 59 | \item{specific}{whether only include specific items in subsets, default is TRUE.} 60 | 61 | \item{...}{useless} 62 | } 63 | \value{ 64 | an upset plot 65 | } 66 | \description{ 67 | This function generate a upset plot by creating a composite plot which contains subplots generated by ggplot2. 68 | } 69 | \examples{ 70 | list = list(A = sample(LETTERS, 20), 71 | B = sample(LETTERS, 22), 72 | C = sample(LETTERS, 14), 73 | D = sample(LETTERS, 30, replace = TRUE)) 74 | venn = Venn(list) 75 | plot_upset(venn) 76 | plot_upset(venn, order.intersect.by = "name") 77 | plot_upset(venn, nintersects = 6) 78 | } 79 | -------------------------------------------------------------------------------- /R/get_shape.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' get applicable shape data for Venn object 4 | #' 5 | #' ggVennDiagram stores shapes as internal data. You may see all the shapes by 6 | #' using `plot_shapes()` or `get_shapes()`. 7 | #' 8 | #' @param type type of shape 9 | #' @param shape_id shape id 10 | #' @param nsets number of sets 11 | #' 12 | #' @return a tibble describing specific shape 13 | #' @export 14 | #' 15 | #' @examples 16 | #' get_shape_data(nsets = 4, type = "polygon") 17 | get_shape_data <- function(nsets, type = NULL, shape_id = NULL){ 18 | all_shape = get_shapes() 19 | data = all_shape[all_shape$nsets == nsets,] 20 | if (!is.null(type)) data = data[data$type == type, ] 21 | if (!is.null(shape_id)) data = data[data$shape_id == shape_id, ] 22 | if (nrow(data)>1) { 23 | # message("More than one shapes are available for ", n, " sets Venn plot. ", 24 | # "Will choose the first one.\n", 25 | # "You may explictly select a shape by specify shape_id, and/or type.\n\n") 26 | data = data |> dplyr::arrange(.data$type) 27 | the_id = data[["shape_id"]][[1]] 28 | return(get_shape_by_id(the_id)) 29 | 30 | } else if (nrow(data) == 1) { 31 | return(get_shape_by_id(data$shape_id)) 32 | } else { 33 | stop("No available shape are found under your settings.", 34 | " Run 'get_shapes()' to see all the available shapes.") 35 | } 36 | } 37 | 38 | 39 | #' Get all shapes 40 | #' 41 | #' @return a tibble 42 | #' @export 43 | #' 44 | #' @examples 45 | #' get_shapes() 46 | get_shapes = function(){ 47 | df = lapply(shapes, function(x){ 48 | tibble::tibble(shape_id = get_shape_id(x), 49 | nsets = get_shape_nsets(x), 50 | type = get_shape_type(x)) 51 | }) |> dplyr::bind_rows() 52 | return(df) 53 | } 54 | 55 | #' Specifying a shape 56 | #' 57 | #' @param id shape id 58 | #' 59 | #' @return a shape 60 | #' @export 61 | #' 62 | #' @examples 63 | #' get_shape_by_id("401f") 64 | get_shape_by_id = function(id){ 65 | idx = sapply(shapes, function(x) get_shape_id(x) == id) 66 | if (sum(idx) == 1) return(shapes[idx][[1]]) 67 | } 68 | 69 | get_shape_id = function(x){ 70 | x$shapeId 71 | } 72 | 73 | get_shape_type = function(x){ 74 | x$type 75 | } 76 | 77 | get_shape_nsets = function(x){ 78 | x$nsets 79 | } 80 | 81 | get_shape_setedge = function(x, ...){ 82 | df = x$setEdge 83 | extra = list(...) 84 | extra$id = as.character(seq_len(x$nsets)) 85 | extra = as.data.frame(extra) 86 | df |> dplyr::left_join(extra, by = "id") 87 | } 88 | 89 | get_shape_setlabel = function(x, ...){ 90 | df = x$setLabel 91 | extra = list(...) 92 | extra$id = as.character(seq_len(x$nsets)) 93 | extra = as.data.frame(extra) 94 | df |> dplyr::left_join(extra, by = "id") 95 | } 96 | 97 | get_shape_regionedge = function(x){ 98 | x$regionEdge 99 | } 100 | 101 | get_shape_regionlabel = function(x){ 102 | x$regionLabel 103 | } 104 | -------------------------------------------------------------------------------- /vignettes/VennCalculator.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Venn Calculator" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{VennCalculator} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ## How to use Venn Calculator? 18 | 19 | `ggVennDiagram` has a series of set operation functions, and this can be used as the Venn calculator. 20 | 21 | ```{r setup} 22 | library(ggVennDiagram) 23 | set.seed(20231225) 24 | y = list( 25 | A = sample(letters, 8) |> sort(), 26 | B = sample(letters, 8) |> sort(), 27 | C = sample(letters, 8) |> sort(), 28 | D = sample(letters, 8) |> sort()) 29 | 30 | y 31 | ``` 32 | 33 | First of all, we need to construct a `Venn` class object with this list. If you print this object, it will give meta information of the object. 34 | 35 | ```{r} 36 | venn_y = Venn(y) 37 | 38 | venn_y 39 | ``` 40 | 41 | * Find the overlapping members of two or more sets. 42 | 43 | ```{r} 44 | overlap(venn_y, 1:2) # members in both the first two sets 45 | overlap(venn_y) # members in all the sets 46 | ``` 47 | 48 | * Find the different members between sets and set unions 49 | 50 | ```{r} 51 | discern(venn_y, 1) # members in set 1, but not in the resting sets 52 | discern(venn_y, c("A","B"), 3) # members in set A & B, but not in the 3rd set 53 | ``` 54 | 55 | * Find the specific members in one or more sets 56 | 57 | ```{r} 58 | discern_overlap(venn_y, 1) # specific items in set 1 59 | discern_overlap(venn_y, 1:2) # specific items in set 1 and set 2 60 | ``` 61 | 62 | * Find the union of two or more sets 63 | 64 | ```{r} 65 | unite(venn_y, 1:2) # union of set 1 and 2 66 | unite(venn_y, "all") # union of all four sets 67 | unite(venn_y, c("A", "B", "C")) 68 | ``` 69 | 70 | Combined results were provided as VennPlotData object. 71 | 72 | ```{r} 73 | pd = process_data(venn_y) 74 | pd 75 | ``` 76 | 77 | * `venn_set()`: get set data from the object. 78 | 79 | ```{r} 80 | venn_set(pd) 81 | ``` 82 | 83 | * `venn_region()`: get subsets data from the object. 84 | 85 | ```{r} 86 | venn_region(pd) 87 | ``` 88 | 89 | Please note in order to keep the result concise, the containing items are nested. You may use the following methods to further process it. 90 | 91 | * Method 1 92 | 93 | ```{r} 94 | venn_region(pd) |> tidyr::unnest(item) 95 | ``` 96 | 97 | * Method 2 98 | 99 | ```{r} 100 | venn_region(pd) |> dplyr::rowwise() |> dplyr::mutate(item = paste0(item, collapse = ", ")) 101 | ``` 102 | 103 | 104 | ## Reference 105 | 106 | Some of these above-mentioned functions are originally developed by Turgut Yigit Akyol in `RVenn`. 107 | 108 | * Akyol T (2019). _RVenn: Set Operations for Many Sets_. R package version 1.1.0, 109 | . 110 | -------------------------------------------------------------------------------- /man/ggVennDiagram.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggVennDiagram.R 3 | \name{ggVennDiagram} 4 | \alias{ggVennDiagram} 5 | \title{ggVennDiagram main parser} 6 | \usage{ 7 | ggVennDiagram( 8 | x, 9 | category.names = names(x), 10 | show_intersect = FALSE, 11 | set_color = "black", 12 | set_size = NA, 13 | label = c("both", "count", "percent", "none"), 14 | label_alpha = 0.5, 15 | label_font = "sans", 16 | label_bigInterval = 3L, 17 | label_bigMark = ",", 18 | label_geom = c("label", "text"), 19 | label_color = "black", 20 | label_size = NA, 21 | label_percent_digit = 0, 22 | label_txtWidth = 40, 23 | edge_lty = "solid", 24 | edge_size = 1, 25 | force_upset = FALSE, 26 | nintersects = 20, 27 | order.intersect.by = c("size", "name", "none"), 28 | order.set.by = c("size", "name", "none"), 29 | relative_height = 3, 30 | relative_width = 0.3, 31 | shape_id = NULL, 32 | ... 33 | ) 34 | } 35 | \arguments{ 36 | \item{x}{list of items} 37 | 38 | \item{category.names}{default is names(x)} 39 | 40 | \item{show_intersect}{if TRUE the text can be visualized by `plotly`} 41 | 42 | \item{set_color}{color of set labels ("black")} 43 | 44 | \item{set_size}{size of set labels (NA)} 45 | 46 | \item{label}{format of region labels, select one from c("count","percent","both","none")} 47 | 48 | \item{label_alpha}{set 0 to remove the background of region labels} 49 | 50 | \item{label_font}{font name of labels} 51 | 52 | \item{label_bigInterval}{Position of thousand separator} 53 | 54 | \item{label_bigMark}{Type of thousand separator} 55 | 56 | \item{label_geom}{layer of region labels, choose from c("label", "text")} 57 | 58 | \item{label_color}{color of region labels ("black")} 59 | 60 | \item{label_size}{size of region labels (NA)} 61 | 62 | \item{label_percent_digit}{number of digits when formatting percent label (0)} 63 | 64 | \item{label_txtWidth}{width of text used in showing intersect members, will be ignored unless show_intersection is TRUE (40)} 65 | 66 | \item{edge_lty}{line type of set edges ("solid")} 67 | 68 | \item{edge_size}{line width of set edges (1)} 69 | 70 | \item{force_upset}{if TRUE, will always produce Upset plot no matter how many sets have (FALSE)} 71 | 72 | \item{nintersects}{number of intersects. If NULL, all intersections will show.} 73 | 74 | \item{order.intersect.by}{'size', 'name', or "none"} 75 | 76 | \item{order.set.by}{'size', 'name', or "none"} 77 | 78 | \item{relative_height}{the relative height of top panel in upset plot} 79 | 80 | \item{relative_width}{the relative width of left panel in upset plot} 81 | 82 | \item{shape_id}{specify a shape by id, run `plot_shapes()` to see available shapes (NULL)} 83 | 84 | \item{...}{useless} 85 | } 86 | \value{ 87 | A ggplot object 88 | } 89 | \description{ 90 | ggVennDiagram main parser 91 | } 92 | \details{ 93 | From version 1.4.4, `ggVennDiagram` will plot a upset plot when the number of sets 94 | is more than 7. Besides, user can switch to a upset plot with `upset_plot()` function. 95 | Please check the document of this function. 96 | } 97 | \examples{ 98 | library(ggVennDiagram) 99 | x = list(A=1:5,B=2:7,C=3:6,D=4:9) 100 | ggVennDiagram(x) # 4d venn 101 | ggVennDiagram(x[1:3]) # 3d venn 102 | ggVennDiagram(x[1:2]) # 2d venn 103 | } 104 | -------------------------------------------------------------------------------- /data-raw/shapes.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `shapes` dataset goes here 2 | 3 | rm(list = ls()) 4 | devtools::install_github("gaospecial/shapeMageR") 5 | library(shapeMageR) 6 | 7 | ## code to prepare `ggVennDiagramShapes` dataset goes here 8 | 9 | # construct a object for plotting Venn Diagram 10 | # columns in `shapes` 11 | # - shapeId: shape id, each shape has three components, and belongs to different type 12 | # - type: c("ellipse","triangle","polygon", "circle") 13 | # - nsets: number of sets, 1:7 14 | # - component: c("setEdge","setLabel","regionEdge","regionLabel") 15 | # - id: id of set/region 16 | # - x, y: coordination of edges/labels 17 | 18 | 19 | # 4d ellipse 20 | f4e = VennShape( 21 | shapeId = "401f", 22 | type = "ellipse", 23 | setEdge = fancy_4d_ellipse(), # how to store object in data.frame 24 | setLabel = fancy_4d_ellipse_label()) 25 | 26 | 27 | # 3d circle 28 | f3c = VennShape( 29 | setEdge = fancy_3d_circle(), 30 | setLabel = fancy_3d_circle_label(), 31 | shapeId = "301f", 32 | type = "circle") 33 | 34 | # 2d circle 35 | f2c = VennShape( 36 | setEdge = fancy_2d_circle(), 37 | setLabel = fancy_2d_circle_label(), 38 | shapeId = "201f", 39 | type = "circle") 40 | 41 | # 6d triangle 42 | f6t = VennShape( 43 | setEdge = fancy_6d_triangle(), 44 | setLabel = fancy_6d_triangle_label(), 45 | shapeId = "601t", 46 | type = "triangle") 47 | 48 | ####### Deal with venn datasets ######## 49 | 50 | # import venn:::sets dataset 51 | sets = venn:::sets |> 52 | dplyr::filter(!is.na(x), !is.na(y)) 53 | colnames(sets) = c("nsets", "shapeId", "id", "x", "y") 54 | sets = sets |> 55 | dplyr::mutate(shapeId = paste(nsets, shapeId + 1, sep = "0")) 56 | 57 | # label position indicated by venn:::scoords 58 | scoords = venn:::scoords 59 | colnames(scoords) = c("nsets", "shapeId", "x", "y") 60 | scoords = scoords |> dplyr::mutate(shapeId = paste(nsets, shapeId + 1, sep = "0"), 61 | id = dplyr::row_number(), 62 | .by = c(nsets, shapeId)) 63 | 64 | sets = sets |> # nest two times 65 | tidyr::nest(xy = c(x, y), .by = nsets:id) |> 66 | tidyr::nest(geometry = c(xy), .by = nsets:shapeId) 67 | sets$type = c(rep("circle", times = 3), 68 | "ellipse", 69 | rep("polygon", times = 5)) 70 | scoords = scoords |> 71 | tidyr::nest(xy = c(x, y), .by = nsets:id) |> 72 | tidyr::nest(geometry = c(xy), .by = nsets:shapeId) 73 | 74 | if(nrow(sets) != nrow(scoords)){ 75 | stop("Set edges and labels are not paired. Please check!") 76 | } 77 | 78 | venn_shapes = lapply(seq_len(nrow(sets)), function(i){ 79 | id = sets$shapeId[[i]] 80 | type = sets$type[[i]] 81 | edge = sets$geometry[[i]][["xy"]] 82 | edge = lapply(edge, as.matrix) 83 | label = scoords$geometry[[which(scoords$shapeId == id)]][["xy"]] 84 | label = lapply(label, as.matrix) 85 | VennShape(setEdge = edge, setLabel = label, shapeId = id, type = type) 86 | }) 87 | 88 | shapes = 89 | c(list(f4e), list(f3c), list(f2c), list(f6t), venn_shapes) 90 | shapes = lapply(shapes, function(x){ 91 | tryCatch(unclass(x), error = function(e) NULL) 92 | }) 93 | shapes = shapes[!sapply(shapes, is.null)] 94 | sortby = sapply(shapes, get_shape_nsets) |> order() 95 | shapes = shapes[sortby] 96 | shapes = lapply(shapes, function(x){ 97 | class(x) = "VennPlotData" 98 | return(x) 99 | }) 100 | usethis::use_data(shapes, overwrite = TRUE, internal = TRUE) 101 | -------------------------------------------------------------------------------- /vignettes/using-new-shapes.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using New Shapes in Venn Diagram" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Using New Shapes in Venn Diagram} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | 18 | ```{r setup} 19 | library(ggVennDiagram) 20 | ``` 21 | 22 | ## Internal Shapes 23 | 24 | The **ggVennDiagram** package has a set of built-in shapes that are used to plot 25 | Venn diagram. These internal data are stored as sys data as a tibble. It can be 26 | accessed with `ggVennDiagram:::shapes` and viewed by the function `get_shapes()`, 27 | and plotted with the function `plot_shapes()`. 28 | 29 | ```{r} 30 | shape1 = ggVennDiagram:::shapes[[4]] 31 | shape1 32 | ``` 33 | The format of these shapes data are defined in `VennPlotData` class. Use `?VennPlotData` to view the document. 34 | 35 | ```{r} 36 | plot_shape_edge(shape1) 37 | ``` 38 | 39 | `get_shapes()` will extract the meta features of these shapes and output a tibble. These information can be used for sepecifying a shape either by its id, or type. 40 | 41 | ```{r} 42 | get_shapes() 43 | ``` 44 | 45 | For example, if you want to extract the shape whose id is "401f". This time we use `ggplot2` functions to plot the set edge of it. 46 | 47 | ```{r} 48 | library(ggplot2) 49 | shape2 = get_shape_by_id("401f") 50 | plot_shape_edge(shape2) 51 | ``` 52 | 53 | The `plot_shapes()` function can be used to plot all the available shapes stored in this package. 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. 54 | 55 | 56 | ```{r} 57 | plot_shapes() 58 | ``` 59 | 60 | Among them, the shapes with less than four sets can be generated with circle or ellipses. For example, the parameters used to generate four-set ellipses were adopted from `VennDiagram` (). Notably, those shapes of five or more sets, including 501, 502, 601, and 701, are created by Adrian Dușa and provided in his `venn` package (). Besides, the 601t shape is imported from a WiKi entry (). 61 | 62 | 63 | ## Using alternative internal shapes 64 | 65 | By default, only the most appropriate shape is used when calling the main function 66 | `ggVennDiagram()`. However, it may be specified in step wise plot which has been 67 | described in [fully customed plot](https://gaospecial.github.io/ggVennDiagram/articles/fully-customed). 68 | 69 | For example: 70 | 71 | 72 | ```{r} 73 | # Generate example data. 74 | genes <- paste0("gene",1:1000) 75 | set.seed(20210701) 76 | gene_list <- list(A = sample(genes,100), 77 | B = sample(genes,200), 78 | C = sample(genes,300), 79 | D = sample(genes,200)) 80 | 81 | # construct a Venn object 82 | venn = Venn(gene_list) 83 | data = process_data(venn, shape_id = "402") 84 | plot_venn(data) 85 | ``` 86 | 87 | ## Using a novel shape 88 | 89 | If user knows the coordinates of a novel shape, it may also be used to draw in 90 | `ggVennDiagram`. The functions of this part have been transfered to a new R package 91 | `shapeMageR`, which can be found in . 92 | To do this, the dependency of `ggVennDiagram` is very light, thus increase the 93 | accessibility of the package. 94 | 95 | 96 | ## Reference 97 | 98 | Adrian Dușa (2024) _venn: Draw Venn Diagrams_, R package version 1.12. . 99 | 100 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # Changelog of ggVennDiagram 2 | 3 | ## ggVennDiagram 1.5.6 4 | 5 | * Add a param `sets.bar.position` (default is "left", can be set to "right") to allow left side layout of barplot in `plot_upset()`. See [#78](https://github.com/gaospecial/ggVennDiagram/issues/78). 6 | 7 | ## ggVennDiagram 1.5.3 8 | 9 | * Add a param to allow user specifying shape by id. See #60. 10 | 11 | ## ggVennDiagram 1.5.2 12 | 13 | * Add a switch to show non-specific items in `plot_upset`. See #64. 14 | 15 | ## ggVennDiagram 1.5.1 16 | 17 | * Add more param to `plot_upset()` function 18 | * Add vignette of Venn Calculator 19 | 20 | ## ggVennDiagram 1.5.0 21 | 22 | * This is a CRAN release 23 | 24 | ## ggVennDiagram 1.4.8 25 | 26 | * add native support to upset plot. Upset plot will be automatically called when nsets > 7. Besides, it can be used by using `upset_plot()` function. See `?upset_plot` for more information. 27 | * a simple shiny app. Run `launch_app()` to use ggVennDiagram interactively. 28 | 29 | ## ggVennDiagram 1.4 30 | 31 | * remove the dependency of `sf`, `purrr`, etc. It is now easy to install. 32 | * add a `print()` method for VennPlotData object. 33 | * add a `show()` method for Venn object. 34 | * `VennPlotData` now store shape and datasets in ordinary data.frames. See `?VennPlotData` for more information. 35 | * many other optimization. 36 | 37 | ## ggVennDiagram 1.2.3 38 | 39 | * Minor fixing for ggplot 3.4 40 | 41 | ## ggVennDiagram 1.2.2 42 | 43 | * I removed the package dependency to `stringr` 44 | 45 | ## ggVennDiagram 1.2 46 | 47 | * Paper published. doi: 10.3389/fgene.2021.706907 48 | * minor fixing of URL 49 | * minor changes 50 | 51 | ## ggVennDiagram 1.1.4 52 | 53 | * minor changes and bug fixing 54 | 55 | ## ggVennDiagram 1.1.3 56 | 57 | * we now export more internal functions which are used in internal data process, 58 | this allow the users to use novel shapes with there data. 59 | * the vignette has benn split to three by topics, and a new vignette was added. 60 | * document has been updated, including pkgdown settings. 61 | 62 | ## ggVennDiagram 1.1.2 63 | 64 | * setup GitHub actions 65 | * enable GitHub pages: https://gaospecial.github.io/ggVennDiagram/index.html 66 | * setup Code Coverage analysis 67 | 68 | ## ggVennDiagram 1.1.1 69 | 70 | * add pkgdown docments 71 | 72 | ## ggVennDiagram 1.1 73 | 74 | * more handy parameters were added to `ggVennDiagram()`, make it much easier to set edge/setlabel/regionlabel color and size. 75 | * some default parameter was reset to previous values in consideration of compatible. 76 | * we released a online book to show detailed usage at https://venn.bio-spring.info. 77 | 78 | ## ggVennDiagram 1.0 79 | 80 | * We completely rebuild `ggVennDiagram` in v1.0. It is now has well-defined data structure and maybe more elegant in coding. 81 | * Although all of the main functions are retained, the usage of a few functions has been modified. This may cause capacity issues. 82 | * If you find a bug or have questions, feel free to open a issue in [GitHub](https://github.com/gaospecial/ggVennDiagram/issues). 83 | 84 | ### Features 85 | 86 | * user can modify the edge/label just use ordinary ggplot functions, without extra knowledge. 87 | * support up to 7 sets Venn diagram, based on the polygon data imported from package `venn`, which is another Venn plot tool authored by Adrian Dusa. 88 | * less memory usage and maybe more faster. 89 | * a lot of helper functions. 90 | 91 | ### Changes 92 | 93 | * if you set `show_intersect = TRUE` in the `ggVennDiagram()` function, it will now return a html widget directly by `plotly`. 94 | * several parameters are removed from the main function `ggVennDiagram()`, including `lty`, `color`, and so on. But these settings can be easily accessed with ggplot functions. See [README](./README.md). 95 | 96 | ## ggVennDiagram 0.5 97 | 98 | * Intersection values can be obtained and visualized now. See [README](./README.md) for more information; 99 | 100 | * Bug fixings. 101 | -------------------------------------------------------------------------------- /R/classVenn.R: -------------------------------------------------------------------------------- 1 | ############ Class Venn ##################### 2 | # 3 | # The Venn class is defined originally in RVenn package by *Turgut Yigit Akyol*. 4 | # It set a good model in calculating the subsets between different sets. 5 | # However, RVenn has not been updated since 2019. I communicate with 6 | # its author and he agreed to transfer some of the codes from RVenn to 7 | # ggVennDiagram. 8 | 9 | #' *`Venn`* is a S4 class to represent multiple sets. 10 | #' @md 11 | #' @slot sets A \code{list} object containing vectors in the same type. 12 | #' @slot names The names of the \code{sets} if it has names. If the \code{list} 13 | #' doesn't have names, the sets will be named as "Set_1", "Set_2", "Set_3" and 14 | #' so on. 15 | #' @name Venn-class 16 | setClass("Venn", 17 | slots = list(sets = "ANY", names = "ANY") 18 | ) 19 | 20 | 21 | ######### Venn Constructor ##### 22 | 23 | #' @title `Venn()` is a Venn class object constructor. 24 | #' 25 | #' @param sets (Required) A list containing vectors in the same class. If a 26 | #' vector contains duplicates they will be discarded. If the list doesn't have 27 | #' names the sets will be named as "Set_1", "Set_2", "Set_3" and so on. 28 | #' @param names names of sets 29 | #' 30 | #' @return A `Venn` object. 31 | #' @rdname Venn-class 32 | #' @docType methods 33 | #' @export 34 | #' @md 35 | #' @examples 36 | #' venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) 37 | #' print(venn) 38 | setGeneric("Venn", function(sets, names = NULL){ 39 | standardGeneric("Venn") 40 | }) 41 | 42 | 43 | #' @export 44 | #' @rdname Venn-class 45 | #' @importFrom methods new 46 | setMethod("Venn", c(sets = "ANY", names = "ANY"), 47 | function(sets, names = NULL){ 48 | # validate parameters 49 | if (!is.list(sets)) { 50 | stop("Data should be given in a list.") 51 | } 52 | 53 | if (length(sets) <= 1) { 54 | stop("The list should contain at least 2 vectors.") 55 | } 56 | 57 | if (!all_identical(lapply(sets, class))){ 58 | stop("All sets should have same classes.") 59 | } 60 | 61 | # check and assign valid set names 62 | if (!is.null(names)){ 63 | if (length(sets) != length(names)) stop("Lengths of sets and names are not equal.") 64 | } else if (is.null(names(sets))){ 65 | names = paste("Set", seq_len(length(sets)), sep = "_") 66 | } else { 67 | names = names(sets) 68 | } 69 | 70 | # remove duplicates 71 | sets = lapply(sets, unique) 72 | 73 | # constructor 74 | data = new(Class = "Venn", 75 | sets = sets, 76 | names = names) 77 | 78 | return(data) 79 | }) 80 | 81 | ######## Helper functions ######## 82 | 83 | #' All members of a list have the same elements 84 | #' 85 | #' @param list a list 86 | #' @return TRUE or FALSE 87 | all_identical = function(list){ 88 | if (!is.list(list)) stop("Input should be a list.") 89 | n = length(list) 90 | if (n <= 1){ 91 | warning("list has less than 2 items.") 92 | invisible() 93 | } else if (n <= 2){ 94 | identical(list[[1]], list[[2]]) 95 | } else { 96 | all(sapply(list[-1], identical, x = list[[1]])) 97 | } 98 | } 99 | 100 | #' method for S4 Venn object 101 | #' 102 | #' Print user-friendly information of a Venn object 103 | #' 104 | #' @param object a Venn class object 105 | #' @export 106 | #' @method show Venn 107 | #' @importFrom methods show slotNames slot 108 | #' @rdname Venn-class 109 | setMethod("show", c(object = "Venn"), 110 | function(object){ 111 | cat("An object of class 'Venn':\n") 112 | cat(" Slots: ", paste0(slotNames(object), collapse = ", "), ";\n", sep = "") 113 | cat(" No. Sets:", length(object@sets)) 114 | cat(" SetNames: ", paste0(slot(object, "names"), collapse = ", "), ".\n", sep = "") 115 | }) 116 | 117 | -------------------------------------------------------------------------------- /vignettes/using-ggVennDiagram.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Tutorial: Using ggVennDiagram" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Tutorial: Using ggVennDiagram} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>", 14 | fig.width = 7, 15 | fig.asp = 0.618, 16 | fig.align = "center" 17 | ) 18 | ``` 19 | 20 | 21 | '`ggVennDiagram`' enables fancy Venn plot with 2-7 sets and generates publication quality figure. 22 | 23 | ## Installation 24 | 25 | You can install the released version of ggVennDiagram from [CRAN](https://CRAN.R-project.org) with: 26 | 27 | ``` r 28 | install.packages("ggVennDiagram") 29 | ``` 30 | 31 | And the development version from [GitHub](https://github.com/) with: 32 | 33 | ``` r 34 | # install.packages("devtools") 35 | devtools::install_github("gaospecial/ggVennDiagram") 36 | ``` 37 | 38 | ## Usage 39 | 40 | Generate example data. 41 | 42 | ```{r} 43 | genes <- paste0("gene",1:1000) 44 | set.seed(20210302) 45 | gene_list <- list(A = sample(genes,100), 46 | B = sample(genes,200), 47 | C = sample(genes,300), 48 | D = sample(genes,200)) 49 | 50 | library(ggVennDiagram) 51 | library(ggplot2) 52 | ``` 53 | 54 | ## long category names 55 | 56 | If you use long category names in Venn plot, labels may be cropped by plot borders. 57 | To avoid this, just use a ggplot trick to expand x axis. 58 | 59 | ```{r} 60 | p1 <- ggVennDiagram(gene_list, 61 | category.names = c("a very long name","short name","name","another name")) 62 | p1 63 | 64 | # expand axis to show long set labels 65 | p1 + scale_x_continuous(expand = expansion(mult = .2)) 66 | ``` 67 | 68 | ## Show intersection values 69 | 70 | When intersection values only have several members, `ggVennDiagram` is efficient to show the values in places. 71 | 72 | ```{r} 73 | set.seed(0) 74 | small_list <- lapply(sample(6:10, size = 4), function(x){ 75 | sample(letters,x) 76 | }) 77 | 78 | ggVennDiagram(small_list, 79 | category.names = LETTERS[1:4], 80 | show_intersect = TRUE) 81 | ``` 82 | 83 | 84 | 85 | ## Setting set label 86 | 87 | ### color of set label 88 | 89 | ```{r} 90 | ggVennDiagram(gene_list, set_color = c("blue","black","red","yellow")) 91 | ``` 92 | 93 | ### size of set labels 94 | 95 | ```{r} 96 | ggVennDiagram(gene_list, set_size = 8) 97 | ``` 98 | 99 | 100 | ## Setting region label 101 | 102 | ### text content 103 | 104 | 105 | 106 | ```{r eval=FALSE} 107 | ggVennDiagram(gene_list, label = "count") 108 | ggVennDiagram(gene_list, label = "percent") 109 | ggVennDiagram(gene_list, label = "both") 110 | ggVennDiagram(gene_list, label = "none") 111 | ``` 112 | 113 | ```{r fig.width=12, echo=FALSE} 114 | plots = lapply(c("none","count","percent","both"), function(x){ 115 | ggVennDiagram(gene_list,label = x) + 116 | labs(title = paste0('label = "', x, '"')) + 117 | theme(legend.position = "none") 118 | }) 119 | aplot::plot_list(gglist = plots) 120 | ``` 121 | 122 | ### percentage digits 123 | 124 | ```{r} 125 | ggVennDiagram(gene_list, label_percent_digit = 1, label = "percent") 126 | ``` 127 | 128 | 129 | ### remove label background 130 | 131 | - Method 1: set alpha to 0 132 | 133 | ```{r} 134 | ggVennDiagram(gene_list, label_alpha = 0) 135 | ``` 136 | 137 | - Method 2: use `geom_text()` 138 | 139 | ```{r} 140 | ggVennDiagram(gene_list, label_geom = "text") 141 | ``` 142 | 143 | ### color and size 144 | 145 | ```{r} 146 | ggVennDiagram(gene_list, label_color = "firebrick", label_size = 4) 147 | ``` 148 | 149 | 150 | ## Setting set edges 151 | 152 | ```{r} 153 | ggVennDiagram(gene_list, edge_lty = "dashed", edge_size = 1) 154 | ``` 155 | 156 | 157 | ## Changing palette 158 | 159 | - changing fill palette 160 | 161 | ```{r} 162 | library(ggplot2) 163 | p <- ggVennDiagram(gene_list) 164 | 165 | # Red Blue 166 | p + scale_fill_distiller(palette = "RdBu") 167 | 168 | # Reds 169 | p + scale_fill_distiller(palette = "Reds", direction = 1) 170 | ``` 171 | 172 | Some other palletes are: 173 | 174 | ```{r fig.asp=2, fig.width=4} 175 | RColorBrewer::display.brewer.all() 176 | ``` 177 | 178 | 179 | ## Adding note 180 | 181 | ```{r} 182 | p + labs(title = "Fancy Venn Diagram of four sets", 183 | subtitle = "Generated by `ggVennDiagram`", 184 | caption = Sys.Date()) 185 | ``` 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /inst/cli/run_ggVennDiagram.R: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env Rscript 2 | # Copyright 2023-2023 Chun-Hui Gao 3 | # 4 | # This file is free software: you may copy, redistribute and/or modify it 5 | # under the terms of the GNU General Public License as published by the 6 | # Free Software Foundation, either version 2 of the License, or (at your 7 | # option) any later version. 8 | # 9 | # This file is distributed in the hope that it will be useful, but 10 | # WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # This script is a standalone R wrapper that can be used to plot Venn and Upset plot 18 | # using ggVennDiagram. It is for command line interface and can be used to build a 19 | # TBtools plugin. 20 | 21 | ##### STEPS ##### 22 | 23 | #### install R - firstly install RServer plugin #### 24 | 25 | 26 | #### install package #### 27 | if (!requireNamespace("pak", quietly = TRUE)){ 28 | install.packages("pak") 29 | } 30 | 31 | if (!requireNamespace("ggVennDiagram", quietly = TRUE)){ 32 | pak::pak("ggVennDiagram") 33 | } 34 | 35 | if (!requireNamespace("argparse", quietly = TRUE)){ 36 | pak::pak("argparse") 37 | } 38 | 39 | library("ggVennDiagram") 40 | library("argparse") 41 | 42 | #### process arguments #### 43 | ## see https://docs.python.org/3/library/argparse.html#the-add-argument-method 44 | parser <- ArgumentParser(description='This is a ggVennDiagram wrapper, 45 | by which you can instantly create publication quality 46 | Venn diagram (no more than 7 sets) and Upset plots 47 | (unlimited No. of sets). For example: PROGRAM -s a,b,c b,c,d e,f') 48 | parser$add_argument('--set', '-s', nargs = '+', help='set members. must be comma separated string. at least one set is needed.') 49 | parser$add_argument('--force-upset', default = FALSE, help = 'specifiy the type of plot') 50 | parser$add_argument("--out", "-o", default = "plot.png",help = "specify the output file of plot. filetype (png/jpg/pdf) is determined by its suffix automatically.") 51 | parser$add_argument("--name", default = NULL, help = "specify the names of sets (Set_1, Set_2, ...)") 52 | parser$add_argument("--set-label-color", default = "black", help = 'color of set labels ("black")') 53 | parser$add_argument("--set-label-size", default = "NA", help = "size of set labels (NA)" ) 54 | parser$add_argument("--label", choices = c("count","percent","both","none"), help = 'format of region labels') 55 | parser$add_argument("--label-alpha", default = 0.5, help = "set 0 to remove the background of region labels") 56 | parser$add_argument('--label-geom', default = "label", choices = c("label", "text"), help = 'layer of region labels, choose from c("label", "text")') 57 | parser$add_argument('--label-color', default = "black", help = 'color of region labels ("black")') 58 | parser$add_argument('--label-size', default = "NA", help = 'size of region labels (NA)') 59 | parser$add_argument('--label-percent-digit', default = 0, help = 'number of digits when formatting percent label (0)') 60 | parser$add_argument('--label-txt-width', default = 40, help = 'width of text used in showing intersect members, will be ignored unless show_intersection is TRUE (40)') 61 | parser$add_argument('--edge-lty', default = "solid", help = 'line type of set edges ("solid")') 62 | parser$add_argument('--edge-size', default = 1, help = 'line width of set edges (1)') 63 | 64 | # parser$print_help() 65 | 66 | args = parser$parse_args() 67 | args = lapply(args, function(x) ifelse(x == "NA", NA, x)) 68 | 69 | list = as.list(args$set) 70 | 71 | #### output results #### 72 | ## plot a png/jpg/tiff, and can export as both PDF and PPTX 73 | p = ggVennDiagram(list, 74 | category.names = args$name, 75 | set_color = args$set_label_color, 76 | set_size = args$set_label_size, 77 | label = args$label, 78 | label_alpha = args$label_alpha, 79 | label_geom = args$label_geom, 80 | label_color = args$label_color, 81 | label_size = args$label_size, 82 | label_percent_digit = args$label_percent_digit, 83 | label_txtWidth = args$label_txt_width, 84 | edge_lty = args$edge_lty, 85 | edge_size = args$edge_size, 86 | force_upset = args$force_upset) 87 | ggplot2::ggsave(args$out, p) 88 | -------------------------------------------------------------------------------- /vignettes/fully-customed.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Fully Customed Venn Diagram" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Fully Customed Venn Diagram} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ```{r setup} 18 | library(ggVennDiagram) 19 | ``` 20 | 21 | ## Comprehensive customization by using helper functions 22 | 23 | The main function `ggVennDiagram()` accepts a list input, and output a ggplot object. 24 | By measuring the length of input list, it automatically applies internal functions 25 | to build a plot in two steps: data preparation and visualization. 26 | 27 | Data preparation was packaged into one function `process_data()`. Its output 28 | is a S4 `VennPlotData` class object, which contains three slots, `setEdge`, 29 | `setLabel` and `region`. These slot data then can be further plotted with `ggplot` 30 | functions. 31 | 32 | See below for a better understanding. 33 | 34 | Generate example data. 35 | 36 | ```{r} 37 | genes <- paste0("gene",1:1000) 38 | set.seed(20231214) 39 | gene_list <- list(A = sample(genes,100), 40 | B = sample(genes,200), 41 | C = sample(genes,300), 42 | D = sample(genes,200)) 43 | ``` 44 | 45 | 46 | ```{r} 47 | library(ggVennDiagram) 48 | library(ggplot2) 49 | ``` 50 | 51 | Then we can reproduce the plot of `ggVennDiagram()` with several lines. 52 | 53 | ```{r} 54 | venn <- Venn(gene_list) 55 | data <- process_data(venn) 56 | ggplot() + 57 | # 1. region count layer 58 | geom_polygon(aes(X, Y, fill = count, group = id), 59 | data = venn_regionedge(data)) + 60 | # 2. set edge layer 61 | geom_path(aes(X, Y, color = id, group = id), 62 | data = venn_setedge(data), 63 | show.legend = FALSE) + 64 | # 3. set label layer 65 | geom_text(aes(X, Y, label = name), 66 | data = venn_setlabel(data)) + 67 | # 4. region label layer 68 | geom_label(aes(X, Y, label = count), 69 | data = venn_regionlabel(data)) + 70 | coord_equal() + 71 | theme_void() 72 | ``` 73 | 74 | The variable `data` is a structured list that has three slots. 75 | 76 | ```{r} 77 | data 78 | ``` 79 | 80 | 81 | `ggVennDiagram` export functions to get these data, and they can be used 82 | for comprehensive customization in user-side. 83 | 84 | - `Venn()`: Venn object constructor, use this to construct a Venn object from list. 85 | - `process_data()`: process data with a Venn object 86 | - `venn_regionedge()`: get region edge data to plot 87 | - `venn_regionlabel()`: get region label position to plot 88 | - `venn_setedge()`: get setedge data to plot 89 | - `venn_setlabel()`: get setlabel data to plot 90 | 91 | 92 | For example, you may change edge/fill/label properties as you will. 93 | 94 | ```{r} 95 | ggplot() + 96 | # change mapping of color filling 97 | geom_polygon(aes(X, Y, fill = id, group = id), 98 | data = venn_regionedge(data), 99 | show.legend = FALSE) + 100 | # adjust edge size and color 101 | geom_path(aes(X, Y, color = id, group = id), 102 | data = venn_setedge(data), 103 | linewidth = 3, 104 | show.legend = FALSE) + 105 | # show set label in bold 106 | geom_text(aes(X, Y, label = name), 107 | fontface = "bold", 108 | data = venn_setlabel(data)) + 109 | # add a alternative region name 110 | geom_label(aes(X, Y, label = id), 111 | data = venn_regionlabel(data), 112 | alpha = 0.5) + 113 | coord_equal() + 114 | theme_void() 115 | ``` 116 | 117 | ## Access to classes 118 | 119 | ```{r} 120 | set.seed(20231225) 121 | y = list( 122 | A = sample(letters, 8) |> sort(), 123 | B = sample(letters, 8) |> sort(), 124 | C = sample(letters, 8) |> sort(), 125 | D = sample(letters, 8) |> sort()) 126 | 127 | # view the list 128 | y 129 | ``` 130 | 131 | ### Access to subset items 132 | 133 | To view subset itmes interactively, set `show_intersect = TRUE`. 134 | 135 | ```{r} 136 | ggVennDiagram(y, show_intersect = TRUE, set_color = "black") 137 | ``` 138 | 139 | 140 | ```{r} 141 | venn_y = Venn(y) 142 | 143 | venn_y 144 | ``` 145 | 146 | 147 | 148 | ```{r} 149 | # find the overlaping members of two or more sets 150 | overlap(venn_y, 1:2) # members in both the first two sets 151 | overlap(venn_y) # members in all the sets 152 | 153 | # find the different members between sets and set unions 154 | discern(venn_y, 1) # members in set 1, but not in all the resting sets by default 155 | discern(venn_y, c("A","B"), 3) # members in set A & B, but not in the third set 156 | 157 | # find the specific members in one or more sets 158 | discern_overlap(venn_y, 1) # specific items in set 1, equals to `discern(venn_y, 1)`. Those members are not shared by all the other sets. 159 | discern_overlap(venn_y, 1:2) # specific items in set 1 and set 2 160 | ``` 161 | 162 | 163 | ### Access to plot data 164 | 165 | ```{r} 166 | venn_plot_data = process_data(venn_y) 167 | 168 | # summary of VennPlotData object 169 | venn_plot_data 170 | ``` 171 | 172 | Sets and labels 173 | 174 | ```{r} 175 | # get the set data 176 | venn_set(venn_plot_data) 177 | 178 | # get subsets, i.e., regions 179 | venn_region(venn_plot_data) 180 | ``` 181 | 182 | Polygons. 183 | 184 | ```{r} 185 | # get set edge 186 | venn_setedge(venn_plot_data) 187 | 188 | # get region edge 189 | venn_regionedge(venn_plot_data) 190 | ``` 191 | 192 | ```{r} 193 | df = venn_setedge(venn_plot_data) 194 | plot(df$X, df$Y, asp = 1) 195 | ``` 196 | 197 | -------------------------------------------------------------------------------- /R/process_data.R: -------------------------------------------------------------------------------- 1 | #' get plot data 2 | #' 3 | #' @param venn a Venn object 4 | #' @param nsets This parameter will be set automatically. 5 | #' @param shape_id apply filter to internal shapes. i.e. shape_id = "601" 6 | #' @param type apply filter to internal shapes. i.e. type = "polygon" 7 | #' 8 | #' @details 9 | #' 10 | #' This function will conduct set operations and combine the outputs will 11 | #' stored shapes, thus produce a dataset for plot in next step. 12 | #' 13 | #' Run `get_shapes()` to show all the characteristics of available shapes. 14 | #' Run `plot_shapes()` to view those shapes. 15 | #' 16 | #' @name process_data 17 | #' @docType methods 18 | #' @export 19 | #' @examples 20 | #' \dontrun{ 21 | #' venn = Venn(list(A=1:3,B=2:5,C=4:8)) 22 | #' data = process_data(venn) 23 | #' } 24 | setGeneric("process_data", function(venn, nsets = NULL, shape_id = NULL, type = NULL){ 25 | standardGeneric("process_data") 26 | }) 27 | 28 | #' @rdname process_data 29 | #' @export 30 | setMethod("process_data", signature = c(venn = "Venn"), 31 | function(venn, 32 | nsets = length(venn@sets), 33 | shape_id = NULL, 34 | type = NULL){ 35 | shape = get_shape_data(nsets = nsets, shape_id = shape_id, type = type) 36 | plotData_add_venn(plotData = shape, venn = venn) 37 | }) 38 | 39 | 40 | #' Get VennPlotData slot 41 | #' 42 | #' @param obj a list that stores all the data from the S3 class `VennPlotData` object 43 | #' 44 | #' @return a tibble 45 | #' @export 46 | #' @name venn_plot_data 47 | #' 48 | #' @examples 49 | #' venn = Venn(list(A=1:5,B=2:7,C=3:6,D=4:9)) 50 | #' obj = process_data(venn) 51 | #' venn_regionlabel(obj) # return regionLabel data 52 | #' venn_regionedge(obj) # return regionEdge data 53 | #' venn_setlabel(obj) # return setLabel data 54 | #' venn_setedge(obj) # return setEdge data 55 | #' venn_set(obj) # set items 56 | #' venn_region(obj) # region items 57 | venn_regionedge = function(obj){ 58 | if (!inherits(obj, "VennPlotData")) stop("obj should be a VennPlotData object.") 59 | obj$regionEdge |> 60 | dplyr::left_join(venn_region(obj), by = "id") |> 61 | dplyr::as_tibble() 62 | } 63 | 64 | #' @rdname venn_plot_data 65 | #' @export 66 | venn_regionlabel = function(obj){ 67 | if (!inherits(obj, "VennPlotData")) stop("obj should be a VennPlotData object.") 68 | obj$regionLabel |> dplyr::as_tibble() 69 | } 70 | 71 | #' @rdname venn_plot_data 72 | #' @export 73 | venn_setedge = function(obj){ 74 | if (!inherits(obj, "VennPlotData")) stop("obj should be a VennPlotData object.") 75 | obj$setEdge |> dplyr::as_tibble() 76 | } 77 | 78 | #' @rdname venn_plot_data 79 | #' @export 80 | venn_setlabel = function(obj){ 81 | if (!inherits(obj, "VennPlotData")) stop("obj should be a VennPlotData object.") 82 | obj$setLabel |> dplyr::as_tibble() 83 | } 84 | 85 | #' @rdname venn_plot_data 86 | #' @export 87 | venn_set = function(obj){ 88 | if (!inherits(obj, "VennPlotData")) stop("obj should be a VennPlotData object.") 89 | obj$setData |> dplyr::as_tibble() 90 | } 91 | 92 | #' @rdname venn_plot_data 93 | #' @export 94 | venn_region = function(obj){ 95 | if (!inherits(obj, "VennPlotData")) stop("obj should be a VennPlotData object.") 96 | obj$regionData |> dplyr::as_tibble() 97 | } 98 | 99 | #' join the shape data with set data 100 | #' 101 | #' @param plotData a VennPlot object that stores plot shapes 102 | #' @param venn a Venn object that stores set values 103 | #' 104 | #' @export 105 | #' 106 | plotData_add_venn = function(plotData, venn){ 107 | if (!all(c("setLabel","setEdge","regionLabel", "regionEdge") %in% names(plotData))) { 108 | stop("Invalid shape data.") 109 | } 110 | if (!inherits(venn, "Venn")) stop("venn should be a S4 Venn object.") 111 | set_data = process_set_data(venn) 112 | region_data = process_region_data(venn) 113 | set_edge = get_shape_setedge(plotData) 114 | set_label = get_shape_setlabel(plotData) 115 | region_edge = get_shape_regionedge(plotData) 116 | region_label = get_shape_regionlabel(plotData) 117 | plotData$setData = set_data 118 | plotData$setLabel = dplyr::left_join(set_label, set_data, by = "id") 119 | plotData$regionData = region_data 120 | plotData$regionLabel = dplyr::left_join(region_label, region_data, by = "id") 121 | return(plotData) 122 | } 123 | 124 | #' Prepare Venn data 125 | #' 126 | #' @name venn_data 127 | #' @param venn a Venn object 128 | #' @param sep name and id separator for intersections 129 | #' 130 | #' @return a tibble 131 | #' @export 132 | #' 133 | #' @examples 134 | #' x = list( 135 | #' A = sample(letters, 8), 136 | #' B = sample(letters, 8), 137 | #' C = sample(letters, 8), 138 | #' D = sample(letters, 8) 139 | #' ) 140 | #' 141 | #' venn = Venn(x) 142 | #' process_set_data(venn) 143 | #' process_region_data(venn) 144 | process_set_data = function(venn){ 145 | if (!inherits(venn, "Venn")) stop("venn is not a S4 class 'Venn' object.") 146 | tibble::tibble( 147 | id = as.character(seq_along(venn@sets)), 148 | name = venn@names, 149 | item = venn@sets, 150 | count = sapply(venn@sets, length) 151 | ) 152 | } 153 | 154 | #' @rdname venn_data 155 | #' @param specific whether return ONLY specific items for a subset, default is TRUE 156 | #' @details 157 | #' ggVennDiagram, by default, only return the specific subsets of a region. 158 | #' However, sometimes, we want to show all the overlapping items for two or more sets. 159 | #' For example: https://github.com/gaospecial/ggVennDiagram/issues/64 160 | #' Therefore, we add a 'specific' switch to this function. While 'specific = FALSE', 161 | #' the seperator will be changed from "/" to "~", and all the overlapping items 162 | #' will be returned. This feature is useful in plotting upset plot. 163 | #' @export 164 | process_region_data = function(venn, sep = "/", specific = TRUE) { 165 | if (!inherits(venn, "Venn")) stop("venn is not a S4 class 'Venn' object.") 166 | region_items = get_subset_items(venn, specific = specific) 167 | counts = sapply(region_items, length) 168 | region_ids = get_subset_ids(venn, sep = sep) 169 | region_names = get_subset_names(venn, sep = sep) 170 | tibble::tibble( 171 | id = region_ids, 172 | name = region_names, 173 | item = region_items, 174 | count = counts 175 | ) 176 | } 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /R/setOperations.R: -------------------------------------------------------------------------------- 1 | # Note: These codes were transferred from RVenn 1.1.0. 2 | # The author is Turgut Yigit Akyol. 3 | 4 | 5 | # Method for intersection ======================= 6 | 7 | 8 | #' Intersection of many sets. 9 | #' 10 | #' \code{overlap} returns the same elements of the sets in a \code{Venn} object. 11 | #' 12 | #' @param venn (Required) A \code{Venn} object. 13 | #' @param slice (Optional) The names or the indices of sets of interest. Default 14 | #' is "all", meaning the intersection will be calculated for all the sets. 15 | #' @return A vector showing the intersection of the sets. 16 | #' @examples 17 | #' venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) 18 | #' overlap(venn) 19 | #' overlap(venn, slice = c(1, 2)) 20 | #' @name overlap 21 | #' @author tyakyol@gmail.com 22 | setGeneric("overlap", function(venn, slice = "all") { 23 | standardGeneric("overlap") 24 | } 25 | ) 26 | 27 | #' @export 28 | #' @rdname overlap 29 | setMethod("overlap", c(venn = "Venn", slice = "ANY"), 30 | function(venn, slice = "all") { 31 | if (slice[1] != "all") { 32 | venn2 = venn@sets[slice] 33 | inter = Reduce(intersect, venn2) 34 | } else { 35 | inter = Reduce(intersect, venn@sets) 36 | } 37 | 38 | inter 39 | } 40 | ) 41 | 42 | 43 | # Method for union ============================== 44 | 45 | #' Union of many sets. 46 | #' 47 | #' \code{unite} returns the union of the sets in a \code{Venn} object. 48 | #' 49 | #' @param venn (Required) A \code{Venn} object. 50 | #' @param slice (Optional) The names or the indices of sets of interest. Default 51 | #' is "all", meaning the union will be calculated for all the sets. 52 | #' @return A vector showing the union of the sets. 53 | #' @examples 54 | #' venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) 55 | #' unite(venn) 56 | #' unite(venn, slice = c(1, 2)) 57 | #' @name unite 58 | #' @author tyakyol@gmail.com 59 | setGeneric("unite", function(venn, slice = "all") { 60 | standardGeneric("unite") 61 | } 62 | ) 63 | 64 | #' @export 65 | #' @rdname unite 66 | setMethod("unite", c(venn = "Venn", slice = "ANY"), 67 | function(venn, slice = "all") { 68 | slice = slice_idx(venn, slice) 69 | if (slice[1] != "all") { 70 | venn2 = venn@sets[slice] 71 | uni = Reduce(union, venn2) 72 | } else { 73 | uni = Reduce(union, venn@sets) 74 | } 75 | uni 76 | } 77 | ) 78 | 79 | 80 | # Method for difference ========================= 81 | 82 | 83 | #' Set difference. 84 | #' 85 | #' \code{discern} returns the difference between two group of sets selected from 86 | #' a \code{Venn} object. If multiple sets are chosen for the slices, union of 87 | #' those sets will be used. 88 | #' 89 | #' @param venn (Required) A \code{Venn} object. 90 | #' @param slice1 (Required) The name or the index of the set of interest. 91 | #' Multiple sets can be selected. 92 | #' @param slice2 (Optional) The name or the index of the set of interest. 93 | #' Multiple sets can be selected. Default is all the sets except the sets of 94 | #' slice1. 95 | #' @return A vector showing the difference between slice1 and slice2. 96 | #' @examples 97 | #' venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) 98 | #' discern(venn, slice1 = 1) 99 | #' discern(venn, slice1 = c(1, 2), slice2 = 3) 100 | #' @name discern 101 | #' @author tyakyol@gmail.com 102 | setGeneric("discern", function(venn, 103 | slice1, 104 | slice2 = "all") { 105 | standardGeneric("discern") 106 | } 107 | ) 108 | 109 | #' @export 110 | #' @rdname discern 111 | setMethod("discern", c(venn = "Venn", slice1 = "ANY", slice2 = "ANY"), 112 | function(venn, 113 | slice1, 114 | slice2 = "all") { 115 | slice1 = slice_idx(venn, slice1) 116 | slice2 = slice_idx(venn, slice2) 117 | 118 | if (slice2[1] == "all") { 119 | set1 = Reduce(union, venn@sets[slice1]) 120 | set2 = Reduce(union, venn@sets[-slice1]) 121 | differ = setdiff(set1, set2) 122 | } else { 123 | set1 = Reduce(union, venn@sets[slice1]) 124 | set2 = Reduce(union, venn@sets[slice2]) 125 | differ = setdiff(set1, set2) 126 | } 127 | 128 | differ 129 | } 130 | ) 131 | 132 | 133 | # Method for specific region ============= 134 | 135 | #' Calculate region of sets 136 | #' 137 | #' calculate the unique region defined 138 | #' by `Venn` object and the parameter `slice`. 139 | #' 140 | #' @param venn a Venn object 141 | #' @param slice index of Venn members, default is "all" 142 | #' 143 | #' @return region items 144 | #' @export 145 | #' @name discern_overlap 146 | #' @author gaospecial@gmail.com 147 | #' 148 | #' @examples 149 | #' library(ggVennDiagram) 150 | #' venn <- Venn(list(A=1:3,B=2:5,C=c(1L,3L,5L))) 151 | #' 152 | #' discern_overlap(venn, slice = "all") 153 | #' # is equal to 154 | #' overlap(venn, slice = "all") 155 | #' 156 | #' # however, `discern_overlap()` only contains specific region 157 | #' discern_overlap(venn, slice = 1:2) 158 | #' # is different from 159 | #' overlap(venn, slice = 1:2) 160 | setGeneric("discern_overlap", function(venn, slice = "all") standardGeneric("discern_overlap")) 161 | 162 | #' @export 163 | #' @rdname discern_overlap 164 | setMethod("discern_overlap", c(venn="Venn", slice="ANY"), 165 | function(venn, slice = "all"){ 166 | slice = slice_idx(venn, slice) 167 | overlap = overlap(venn, slice = slice) 168 | if (slice[1] == "all" | identical(venn@sets[slice], venn@sets)){ 169 | discern = NULL 170 | return(overlap) 171 | } else { 172 | discern = discern(venn, slice1 = slice, slice2 = "all") 173 | return(intersect(overlap, discern)) 174 | } 175 | }) 176 | 177 | 178 | #' check and format slice name 179 | #' 180 | #' @param venn a Venn object 181 | #' @param slice a numeric or character vector 182 | #' 183 | #' @return the index of Venn (numeric vector) or "all" 184 | slice_idx = function(venn, slice){ 185 | set_name = venn@names 186 | if (is.numeric(slice)){ 187 | found = slice %in% seq_along(set_name) 188 | if (all(found)){ 189 | return(slice) 190 | } else { 191 | stop(paste("slice is not valid:", slice[!found])) 192 | } 193 | } 194 | if (is.character(slice)){ 195 | if (any(slice == "all")){ 196 | return("all") 197 | } else { 198 | matches = match(slice, set_name) 199 | if (all(!is.na(matches))){ 200 | slice = matches 201 | return(slice) 202 | } else { 203 | non_exist_item = slice[is.na(matches)] 204 | stop(paste(non_exist_item, "is not found in this object.")) 205 | } 206 | } 207 | } 208 | stop("slice should either be a character or numeric vector.") 209 | } 210 | -------------------------------------------------------------------------------- /inst/shiny/shinyApp.R: -------------------------------------------------------------------------------- 1 | library(tidyr) 2 | library(shiny) 3 | library(ggVennDiagram) 4 | # devtools::load_all(path = rprojroot::find_root("DESCRIPTION")) 5 | library(ggplot2) 6 | library(bslib) 7 | library(colourpicker) 8 | library(export) 9 | 10 | # SHINY UI ------------------------------------------------------------------ 11 | 12 | ui = page_sidebar( 13 | theme = bs_theme(version = 5), 14 | tags$head( 15 | tags$link(rel = "stylesheet", type = "text/css", href = "shinyApp.css") 16 | ), 17 | title = "ggVennDiagram Shiny App", 18 | sidebar = sidebar( 19 | width = "30%", 20 | # Set number 21 | sliderInput( 22 | inputId = 'nsets', 23 | label = "Number of Sets: ", 24 | value = 3, 25 | min = 2, 26 | max = 8, 27 | step = 1 28 | ), 29 | 30 | p("Set name and members:"), 31 | 32 | # dynamic inputs 33 | uiOutput("text_inputs"), 34 | 35 | accordion( 36 | open = FALSE, 37 | accordion_panel( 38 | "Label Controls", 39 | numericInput("set_size", "size of set label", 5, min = 0, max = 10, step = 1), 40 | selectInput("label", "mode",c("both", "count", "percent", "none"), selected = "both"), 41 | selectInput("label_geom", 'geom', c("text", "label"), selected = "label"), 42 | numericInput("label_alpha", "alpha", 0.5, min = 0, max = 1, step = 0.1), 43 | colourInput("label_color", "color", value = "white"), 44 | numericInput("label_size", "size", 3), 45 | numericInput("label_percent_digit", "digit", 0, step = 1, min = 0, max = 3), 46 | numericInput("label_txtWidth", 'text width', 40, step = 1, min = 1, max = 100) 47 | ), 48 | accordion_panel( 49 | "Edge Controls", 50 | selectInput("edge_lty", "line type", c("solid", "dashed", "dotted", "dotdash", "longdash", "twodash"), selected = "solid"), 51 | numericInput("edge_size", 'size', 1, step = 1, min = 0, max = 10) 52 | ), 53 | accordion_panel( 54 | "Filling Controls", 55 | colourInput("low", "low value color", value = "white", showColour = "both", palette = "limited", closeOnClick = TRUE), 56 | colourInput("high", "high value color", value = "red",showColour = "both", palette = "limited", closeOnClick = TRUE), 57 | ), 58 | accordion_panel( 59 | "Upset Controls", 60 | numericInput("nintersects", "nintersects", 20, min = 1, max = 100, step = 1), 61 | selectInput("order.intersect.by", "order of intersect",c("size", "name", "none"), selected = "none"), 62 | selectInput("order.set.by", 'order of set', c("size", "name", "none"), selected = 'none'), 63 | numericInput("relative_height", 'relative height', 3, min = 2, max = 6, step = 0.1), 64 | numericInput('relative_width', 'relative width', 0.3, min = 0.1, max = 1, step = 0.1) 65 | ), 66 | ), 67 | 68 | fluidRow( 69 | # type of plot 70 | # column(4, 71 | checkboxInput( 72 | inputId = "force_upset", 73 | label = "Upset" 74 | ) 75 | # ), 76 | # column(8, 77 | # checkboxInput( 78 | # "show_intersect", 79 | # "Show Intersects" 80 | # )) 81 | ), 82 | 83 | # 画图按钮 84 | actionButton("plot_btn", "Plot Now!"), 85 | ), 86 | 87 | card( 88 | style = "overflow: visible;", 89 | uiOutput('plot_note'), 90 | 91 | # plot 92 | plotOutput("plot"), 93 | 94 | # download button 95 | conditionalPanel( 96 | condition = "output.plot", 97 | p("Download this plot in different formats:"), 98 | uiOutput("download_btns") 99 | 100 | ) 101 | 102 | ) 103 | ) 104 | 105 | 106 | 107 | 108 | # SERVER SIDE FUNCTIONS --------------------------------------------------- 109 | 110 | 111 | server = function(input, output, session) { 112 | # output format 113 | format = c("png","jpg","tiff","svg","pdf","pptx") 114 | output$download_btns = renderUI({ 115 | dl_list = lapply(format, function(x){ 116 | downloadButton(paste0("download_",x), toupper(x)) 117 | }) 118 | do.call(tagList, dl_list) 119 | }) 120 | 121 | # 动态生成文本输入框的UI 122 | output$text_inputs = renderUI({ 123 | # 生成 nsets 个文本输入框 124 | text_inputs = lapply(1:input$nsets, function(i) { 125 | div( 126 | class = "form-control my-2 p-2", 127 | div( 128 | class = "inline", 129 | textInput(paste0("setname_",i), NULL, paste("Set", i, sep = "_"), width = "60%"), 130 | colourInput(paste0("setcolor_",i), NULL, value = "black", showColour = "both", palette = "limited", closeOnClick = TRUE, width = "40%"), 131 | ), 132 | textAreaInput(paste0("set_", i), 133 | label = "", 134 | value = paste0(sample(letters, sample(3:10, 1)), collapse = ","))) 135 | }) 136 | 137 | # 返回生成的文本输入框列表 138 | do.call(tagList, text_inputs) 139 | }) 140 | 141 | # initialize plot note 142 | output$plot_note = renderUI({ 143 | tagList( 144 | h2("Steps", class = "my-4"), 145 | markdown("1. Use the button or slider to specify the number of sets."), 146 | markdown("2. Specify set members using comma-sparated strings (accept separators are `,`, `;`, `\\t`, `\\n`, or `\\r`)."), 147 | markdown("3. Configure addtional parameters if you want."), 148 | markdown("4. Click the **** button."), 149 | markdown("5. Enjoy and download your publication-quality figures.") 150 | ) 151 | }) 152 | 153 | # 绘图的逻辑 154 | drawPlot <- function(){ 155 | x = vector("list", length = input$nsets) 156 | category_names = vector("list", length = input$nsets) 157 | set_color = vector("list", length = input$nsets) 158 | for (i in 1:input$nsets) { 159 | x[[i]] = input[[paste0("set_", i)]] |> strsplit(split = "[,;\t\n\r]+") |> unlist() 160 | category_names[[i]] = input[[paste0("setname_",i)]] 161 | set_color[[i]] = input[[paste0("setcolor_", i)]] 162 | } 163 | set_color = unlist(set_color) 164 | p = ggVennDiagram(x, 165 | category.names = category_names, 166 | # show_intersect = input$show_intersect, 167 | set_color = set_color, 168 | set_size = input$set_size, 169 | label = input$label, 170 | label_alpha = input$label_alpha, 171 | label_size = input$label_size, 172 | label_percent_digit = input$label_percent_digit, 173 | label_txtWidth = input$label_txtWidth, 174 | edge_lty = input$edge_lty, 175 | edge_size = input$edge_size, 176 | force_upset = input$force_upset, 177 | nintersects = input$nintersects, 178 | order.intersect.by = input$order.intersect.by, 179 | order.set.by = input$order.set.by, 180 | relative_height = input$relative_height, 181 | relative_width = input$relative_width) 182 | if (inherits(p, "upset_plot")){ 183 | return(p) 184 | } else { 185 | return( p + scale_fill_gradient(low = input$low, high = input$high)) 186 | } 187 | 188 | } 189 | 190 | # 监听画图按钮的点击事件 191 | observeEvent(input$plot_btn, { 192 | p = drawPlot() 193 | output$plot = renderPlot(p) 194 | output$plot_note = NULL 195 | session$userData$plot = p 196 | }) 197 | 198 | download_filename = function(format){ 199 | # 获取当前时间 200 | current_time <- Sys.time() 201 | 202 | # 将时间格式化为字符串,例如"2023-12-26_14-30-00" 203 | formatted_time <- format(current_time, format = "%Y-%m-%d_%H-%M-%S") 204 | 205 | # 生成文件名 206 | file_name <- paste0("ggVennDiagram_", formatted_time, ".", format) 207 | 208 | # 打印生成的文件名 209 | return(file_name) 210 | 211 | } 212 | 213 | 214 | # 下载按钮的回调函数 215 | lapply(format, function(x) { 216 | if (x == "pptx"){ 217 | output[[paste0("download_", x)]] = downloadHandler( 218 | filename = download_filename(x), 219 | content = function(file){ 220 | export::graph2ppt(file = file, x = session$userData$plot) 221 | } 222 | ) 223 | } else { 224 | output[[paste0("download_", x)]] = downloadHandler( 225 | filename = download_filename(x), 226 | content = function(file){ 227 | ggsave(file, session$userData$plot, device = x) 228 | } 229 | ) 230 | } 231 | }) 232 | 233 | } 234 | 235 | 236 | # RUN shinyApp() ---------------------------------------------------------- 237 | 238 | shinyApp(ui, server) 239 | -------------------------------------------------------------------------------- /README.rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "90%" 13 | ) 14 | library("badger") 15 | ``` 16 | 17 | # ggVennDiagram 18 | 19 | 20 | `r badge_cran_download("ggVennDiagram", type = "grand-total")` 21 | `r badge_cran_download("ggVennDiagram", type = "last-month")` 22 | `r badge_doi("10.1002/imt2.177", "blue")` 23 | `r badge_cran_release("ggVennDiagram","green")` 24 | `r badge_devel(color = "green")` 25 | `r badge_codecov(token = "c365345d-e34c-40f6-b2c0-881b5b2841e7")` 26 | 27 | 28 | '`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. 29 | 30 | ## Installation 31 | 32 | You can install the released version of ggVennDiagram from [CRAN](https://CRAN.R-project.org) with: 33 | 34 | ``` r 35 | install.packages("ggVennDiagram") 36 | ``` 37 | 38 | And the development version from [GitHub](https://github.com/) with: 39 | 40 | ``` r 41 | # install.packages("devtools") 42 | devtools::install_github("gaospecial/ggVennDiagram") 43 | ``` 44 | 45 | 46 | ## Citation 47 | 48 | If you find **ggVennDiagram** is useful and used it in academic papers, you may cite this package as: 49 | 50 | 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). 51 | 52 | ## Features 53 | 54 | ![](https://vnote-1251564393.cos.ap-chengdu.myqcloud.com/picgo/202403141008626.png) 55 | 56 | **Notes** 57 | 58 | The ggVennDiagram Shiny app can be accessed at Shinyapps.io (https://bio-spring.shinyapps.io/ggVennDiagram), or `ggVennDiagram::launch_app()` in local machine. 59 | 60 | The [TBtools](https://github.com/CJ-Chen/TBtools-II) plugin can be accessed through its plugin store. 61 | 62 | ## Example 63 | 64 | `ggVennDiagram` maps the fill color of each region to quantity, allowing us to visually observe the differences between different parts. 65 | 66 | ```{r} 67 | library(ggVennDiagram) 68 | genes <- paste("gene",1:1000,sep="") 69 | set.seed(20231214) 70 | x <- list(A=sample(genes,300), 71 | B=sample(genes,525), 72 | C=sample(genes,440), 73 | D=sample(genes,350)) 74 | ``` 75 | 76 | ```{r include=FALSE} 77 | devtools::load_all() 78 | ``` 79 | 80 | 81 | `ggVennDiagram` return a `ggplot` object, the fill/edge colors can be further modified with `ggplot` functions. 82 | 83 | ```{r} 84 | library(ggplot2) 85 | ggVennDiagram(x) + scale_fill_gradient(low="grey90",high = "red") 86 | 87 | ggVennDiagram(x, set_color = c("blue","red","green","purple")) 88 | ``` 89 | 90 | `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. 91 | 92 | The parameter `category.names` is set names. And the parameter `label` can label how many items are included in each parts. 93 | 94 | ```{r} 95 | ggVennDiagram(x,category.names = c("Stage 1","Stage 2","Stage 3", "Stage4")) 96 | 97 | ggVennDiagram(x,category.names = c("Stage 1","Stage 2","Stage 3", "Stage4"), label = "none") 98 | ``` 99 | 100 | Set `label_alpha = 0` to remove label background. 101 | 102 | ```{r} 103 | ggVennDiagram(x, label_alpha=0) 104 | ``` 105 | 106 | ## Showing intersection values 107 | 108 | *Note: you need to install the GitHub version to enable these functions.* 109 | 110 | We implemented the `process_region_data()` to get intersection values. 111 | 112 | ```{r} 113 | y <- list( 114 | A = sample(letters, 8), 115 | B = sample(letters, 8), 116 | C = sample(letters, 8), 117 | D = sample(letters, 8) 118 | ) 119 | 120 | process_region_data(Venn(y)) 121 | ``` 122 | 123 | If only several items were included, intersections may also be viewed interactively by `plotly` method (if you have two many items, this is useless). 124 | 125 | 126 | ```{r eval=FALSE} 127 | ggVennDiagram(y, show_intersect = TRUE) 128 | ``` 129 | 130 | In web browser or RStudio, you will get: 131 | 132 | ```{r echo=FALSE} 133 | knitr::include_graphics("https://vnote-1251564393.cos.ap-chengdu.myqcloud.com/typora-img/intersection.gif") 134 | ``` 135 | 136 | # Customizing your plot 137 | 138 | There are three components in a Venn plot: 1) the set labels; 2) the edge of sets; 139 | 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. 140 | 141 | In general, `ggVennDiagram()` plot a Venn in three steps: 142 | 143 | - get the coordinates of a applicable shape from internal `shapes` datasets. 144 | - calculate sub regions of sets, including both the shape regions and sets members, 145 | and return a `VennPlotData` object that includes all necessary definitions. 146 | We implement a number of set operations functions to do this job. 147 | - plot using `ggplot2` functions. 148 | 149 | Please check `vignette("fully-customed", package = "ggVennDiagram")` for more information. 150 | 151 | # Venn Diagram for more than four sets 152 | 153 | If you have reviewed my codes, you may find it is easy to support Venn Diagram for more than four sets, 154 | as soon as you find a ideal parameter to generate more circles or ellipses in the plot. 155 | The key point is to let the generated ellipses have exactly one intersection for each combination. 156 | 157 | ## Venn Diagram of up to seven sets 158 | 159 | 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. 160 | 161 | However, Venn Diagram for more than four sets may be meaningless in some conditions, 162 | as some parts may be omitted in such ellipses. Therefore, it is only useful in specific conditions. 163 | For example, if the set intersection of all group are extremely large, you may use several 164 | ellipses to draw a "flower" to show that. 165 | 166 | ```{r eval=FALSE} 167 | x <- list(A=sample(genes,300), 168 | B=sample(genes,525), 169 | C=sample(genes,440), 170 | D=sample(genes,350), 171 | E=sample(genes,200), 172 | F=sample(genes,150), 173 | G=sample(genes,100)) 174 | 175 | # two dimension Venn plot 176 | ggVennDiagram(x[1:2],label = "none") 177 | 178 | # three dimension Venn plot 179 | ggVennDiagram(x[1:3],label = "none") 180 | 181 | # four dimension Venn plot 182 | ggVennDiagram(x[1:4],label = "none") 183 | 184 | # five dimension Venn plot 185 | ggVennDiagram(x[1:5],label = "none") 186 | 187 | # six dimension Venn plot 188 | ggVennDiagram(x[1:6],label = "none") 189 | 190 | # seven dimension Venn plot 191 | ggVennDiagram(x,label = "none") 192 | ``` 193 | 194 | 195 | ```{r echo=FALSE, fig.asp=1.2,fig.width=6} 196 | set.seed(20210507) 197 | x <- list(A = sample(genes,100), 198 | B = sample(genes,150), 199 | C = sample(genes,200), 200 | D = sample(genes,250), 201 | E = sample(genes,300), 202 | F = sample(genes,350), 203 | G = sample(genes,400)) 204 | plots <- lapply(2:7, function(i) ggVennDiagram(x[1:i],label = "none",edge_size = 0.5) + 205 | labs(title = paste("sets = ", i)) + 206 | scale_fill_distiller(palette = "RdBu") + 207 | theme(legend.position = "none", 208 | title = element_text(hjust = 0.5))) 209 | cowplot::plot_grid(plotlist = plots, ncol = 2) 210 | ``` 211 | 212 | ## Native support of upset plot 213 | 214 | 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. 215 | 216 | ```{r} 217 | # add an extra member in list 218 | x$H = sample(genes,500) 219 | ggVennDiagram(x) 220 | ``` 221 | 222 | Upset plot can also be used by setting `force_upset = TRUE`. 223 | 224 | ```{r} 225 | ggVennDiagram(x[1:4], force_upset = TRUE, order.set.by = "name", order.intersect.by = "none") 226 | ``` 227 | 228 | 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. 229 | 230 | For example, if we want to give more space to lower panel, just change the `relative_height` from 3 (the default) to 2. 231 | 232 | ```{r} 233 | venn = Venn(x) 234 | plot_upset(venn, nintersects = 30, relative_height = 2, relative_width = 0.3) 235 | ``` 236 | 237 | # Reference 238 | 239 | Adrian Dușa (2024) _venn: Draw Venn Diagrams_, R package version 1.12. . 240 | 241 | -------------------------------------------------------------------------------- /R/ggVennDiagram.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' ggVennDiagram main parser 4 | #' 5 | #' @details 6 | #' From version 1.4.4, `ggVennDiagram` will plot a upset plot when the number of sets 7 | #' is more than 7. Besides, user can switch to a upset plot with `upset_plot()` function. 8 | #' Please check the document of this function. 9 | #' 10 | #' 11 | #' @param x list of items 12 | #' @param category.names default is names(x) 13 | #' @param show_intersect if TRUE the text can be visualized by `plotly` 14 | #' @param set_color color of set labels ("black") 15 | #' @param set_size size of set labels (NA) 16 | #' @param label format of region labels, select one from c("count","percent","both","none") 17 | #' @param label_geom layer of region labels, choose from c("label", "text") 18 | #' @param label_alpha set 0 to remove the background of region labels 19 | #' @param label_color color of region labels ("black") 20 | #' @param label_size size of region labels (NA) 21 | #' @param label_font font name of labels 22 | #' @param label_bigMark Type of thousand separator 23 | #' @param label_bigInterval Position of thousand separator 24 | #' @param label_percent_digit number of digits when formatting percent label (0) 25 | #' @param label_txtWidth width of text used in showing intersect members, will be ignored unless show_intersection is TRUE (40) 26 | #' @param edge_lty line type of set edges ("solid") 27 | #' @param edge_size line width of set edges (1) 28 | #' @param force_upset if TRUE, will always produce Upset plot no matter how many sets have (FALSE) 29 | #' @param shape_id specify a shape by id, run `plot_shapes()` to see available shapes (NULL) 30 | #' @inheritParams upset-plot 31 | #' @param ... useless 32 | #' 33 | #' @return A ggplot object 34 | #' @export 35 | #' @examples 36 | #' library(ggVennDiagram) 37 | #' x = list(A=1:5,B=2:7,C=3:6,D=4:9) 38 | #' ggVennDiagram(x) # 4d venn 39 | #' ggVennDiagram(x[1:3]) # 3d venn 40 | #' ggVennDiagram(x[1:2]) # 2d venn 41 | ggVennDiagram = function(x, 42 | category.names = names(x), 43 | show_intersect = FALSE, 44 | set_color = "black", 45 | set_size = NA, 46 | label = c("both","count","percent","none"), 47 | label_alpha = 0.5, 48 | label_font = "sans", 49 | label_bigInterval = 3L, 50 | label_bigMark = ",", 51 | label_geom = c("label","text"), 52 | label_color = "black", 53 | label_size = NA, 54 | label_percent_digit = 0, 55 | label_txtWidth = 40, 56 | edge_lty = "solid", 57 | edge_size = 1, 58 | force_upset = FALSE, 59 | nintersects = 20, 60 | order.intersect.by = c("size","name","none"), 61 | order.set.by = c("size","name","none"), 62 | relative_height = 3, 63 | relative_width = 0.3, 64 | shape_id = NULL, 65 | ...){ 66 | if (!is.list(x)){ 67 | stop(simpleError("ggVennDiagram() requires at least a list.")) 68 | } 69 | names(x) = category.names 70 | dimension = length(x) 71 | venn = Venn(x) 72 | 73 | label = match.arg(label) 74 | label_geom = match.arg(label_geom) 75 | if (dimension <= 7 & !force_upset){ 76 | data = process_data(venn, shape_id = shape_id) 77 | plot_venn(data, 78 | show_intersect = show_intersect, 79 | set_color = set_color, 80 | set_size = set_size, 81 | label = label, 82 | label_alpha=label_alpha, 83 | label_font = label_font, 84 | label_geom = label_geom, 85 | label_color = label_color, 86 | label_size = label_size, 87 | label_bigMark = label_bigMark, 88 | label_bigInterval = label_bigInterval, 89 | label_percent_digit = label_percent_digit, 90 | label_txtWidth = label_txtWidth, 91 | edge_lty = edge_lty, 92 | edge_size = edge_size, 93 | ...) 94 | } 95 | else{ 96 | if (!force_upset) warning("Only support 2-7 dimension Venn diagram. Will give a plain upset plot instead.") 97 | plot_upset(venn, 98 | nintersects = nintersects, 99 | order.intersect.by = order.intersect.by, 100 | order.set.by = order.set.by, 101 | relative_height = relative_height, 102 | relative_width = relative_width, 103 | ...) 104 | } 105 | } 106 | 107 | 108 | 109 | 110 | #' plot codes 111 | #' 112 | #' @inheritParams ggVennDiagram 113 | #' @param data plot data 114 | #' 115 | #' @import ggplot2 116 | #' @export 117 | #' 118 | #' @return ggplot object, or plotly object if show_intersect is TRUE 119 | plot_venn = function(data, 120 | show_intersect = FALSE, 121 | set_color = "black", 122 | set_size = NA, 123 | label = "both", 124 | label_geom = "label", 125 | label_alpha = 0.5, 126 | label_font = "sans", 127 | label_color = "black", 128 | label_size = NA, 129 | label_percent_digit = 0, 130 | label_bigMark = ",", 131 | label_bigInterval = 3L, 132 | label_txtWidth = 40, 133 | edge_lty = "solid", 134 | edge_size = 1, 135 | ...){ 136 | setedge.params = list(data = get_shape_setedge(data, color = set_color, 137 | linetype = edge_lty, 138 | linewidth = as.numeric(edge_size)), 139 | mapping = aes(color = I(.data$color), 140 | group = .data$id, 141 | linetype = I(.data$linetype), 142 | linewidth = I(.data$linewidth)), 143 | show.legend = FALSE) 144 | setlabel.params = list(data = get_shape_setlabel(data, size = as.numeric(set_size), color = set_color), 145 | mapping = aes(label = .data$name, 146 | size = I(.data$size), 147 | color = I(.data$color) 148 | ), 149 | family = label_font, 150 | show.legend = FALSE) 151 | region.params = list(data = get_shape_regionedge(data) |> dplyr::left_join(venn_region(data), by = "id"), 152 | mapping = aes(fill = .data$count, 153 | group = .data$id)) 154 | 155 | setedge.layer = do.call('geom_path', setedge.params) 156 | setlabel.layer = do.call('geom_text', setlabel.params) 157 | region.layer = do.call('geom_polygon', region.params) 158 | 159 | p = ggplot(mapping = aes(.data$X, .data$Y)) 160 | p_nonlabel = p + region.layer + setedge.layer + setlabel.layer + theme_void() + coord_equal() 161 | 162 | if (label == "none"){ 163 | return(p_nonlabel) 164 | } 165 | 166 | # process data for plotting region labels 167 | region_label = get_shape_regionlabel(data) 168 | 169 | # use plotly to show intersect 170 | if (show_intersect){ 171 | check_package("plotly") 172 | region_label = region_label |> 173 | dplyr::rowwise() |> 174 | dplyr::mutate(item = yulab.utils::str_wrap(paste0(.data$item, collapse = " "), 175 | width = label_txtWidth)) 176 | p_plotly = p_nonlabel + 177 | geom_text(aes(label = .data$count, text = .data$item), 178 | data = region_label) + 179 | theme(legend.position = "none") 180 | ax = list( 181 | showline = FALSE 182 | ) 183 | p_plotly = plotly::ggplotly(p_plotly, tooltip = c("text")) |> 184 | plotly::layout(xaxis = ax, yaxis = ax) 185 | return(p_plotly) 186 | } 187 | 188 | # calculate labels, which are 'percent', 'count', or 'both' 189 | region_label = region_label |> 190 | dplyr::mutate(percent = paste(round(.data$count*100/sum(.data$count), 191 | digits = label_percent_digit),"%", sep=""), 192 | both = paste(format(.data$count, big.mark = label_bigMark, big.interval = label_bigInterval),paste0("(",.data$percent,")"),sep = "\n")) 193 | 194 | # if label != "none" & show_intersect == FALSE 195 | if (label_geom == "label"){ 196 | p_label = p_nonlabel + geom_label( 197 | aes(label = .data[[label]]), 198 | data = region_label, 199 | alpha = label_alpha, 200 | family = label_font, 201 | color = label_color, 202 | size = label_size, 203 | lineheight = 0.85, 204 | label.size = NA, 205 | linewidth = 0, 206 | fill = "white" 207 | ) 208 | return(p_label) 209 | } 210 | 211 | if (label_geom == "text"){ 212 | p_label = p_nonlabel + geom_text( 213 | aes(label = .data[[label]]), 214 | data = region_label, 215 | alpha = label_alpha, 216 | family = label_font, 217 | color = label_color, 218 | size = label_size, 219 | lineheight = 0.85 220 | ) 221 | return(p_label) 222 | } 223 | 224 | 225 | } 226 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # ggVennDiagram 5 | 6 | 7 | 8 | [![](http://cranlogs.r-pkg.org/badges/grand-total/ggVennDiagram)](https://cran.r-project.org/package=ggVennDiagram) 9 | [![](http://cranlogs.r-pkg.org/badges/last-month/ggVennDiagram)](https://cran.r-project.org/package=ggVennDiagram) 10 | [![](https://img.shields.io/badge/doi-10.1002/imt2.177-blue.svg)](https://doi.org/10.1002/imt2.177) 11 | [![](https://www.r-pkg.org/badges/version/ggVennDiagram?color=green)](https://cran.r-project.org/package=ggVennDiagram) 12 | [![](https://img.shields.io/badge/devel%20version-1.5.6-green.svg)](https://github.com/gaospecial/ggVennDiagram) 13 | [![](https://codecov.io/gh/gaospecial/ggVennDiagram/branch/master/graph/badge.svg?token=c365345d-e34c-40f6-b2c0-881b5b2841e7)](https://app.codecov.io/gh/gaospecial/ggVennDiagram) 14 | 15 | 16 | ‘`ggVennDiagram`’ enables fancy Venn plot with 2-7 sets and generates 17 | publication quality figure. It also support upset plot with unlimited 18 | number of sets from version 1.4.4. 19 | 20 | ## Installation 21 | 22 | You can install the released version of ggVennDiagram from 23 | [CRAN](https://CRAN.R-project.org) with: 24 | 25 | ``` r 26 | install.packages("ggVennDiagram") 27 | ``` 28 | 29 | And the development version from [GitHub](https://github.com/) with: 30 | 31 | ``` r 32 | # install.packages("devtools") 33 | devtools::install_github("gaospecial/ggVennDiagram") 34 | ``` 35 | 36 | ## Citation 37 | 38 | If you find **ggVennDiagram** is useful and used it in academic papers, 39 | you may cite this package as: 40 | 41 | Gao, C.-H., Chen, C., Akyol, T., Dușa, A., Yu, G., Cao, B., and Cai, P. 42 | (2024). ggVennDiagram: intuitive Venn diagram software extended. 43 | [iMeta](https://onlinelibrary.wiley.com/journal/2770596x) 3, 69. doi: 44 | [10.1002/imt2.177](https://onlinelibrary.wiley.com/doi/full/10.1002/imt2.177). 45 | 46 | ## Features 47 | 48 | ![](https://vnote-1251564393.cos.ap-chengdu.myqcloud.com/picgo/202403141008626.png) 49 | 50 | **Notes** 51 | 52 | The ggVennDiagram Shiny app can be accessed at Shinyapps.io 53 | (), or 54 | `ggVennDiagram::launch_app()` in local machine. 55 | 56 | The [TBtools](https://github.com/CJ-Chen/TBtools-II) plugin can be 57 | accessed through its plugin store. 58 | 59 | ## Example 60 | 61 | `ggVennDiagram` maps the fill color of each region to quantity, allowing 62 | us to visually observe the differences between different parts. 63 | 64 | ``` r 65 | library(ggVennDiagram) 66 | genes <- paste("gene",1:1000,sep="") 67 | set.seed(20231214) 68 | x <- list(A=sample(genes,300), 69 | B=sample(genes,525), 70 | C=sample(genes,440), 71 | D=sample(genes,350)) 72 | ``` 73 | 74 | `ggVennDiagram` return a `ggplot` object, the fill/edge colors can be 75 | further modified with `ggplot` functions. 76 | 77 | ``` r 78 | library(ggplot2) 79 | ggVennDiagram(x) + scale_fill_gradient(low="grey90",high = "red") 80 | ``` 81 | 82 | 83 | 84 | ``` r 85 | 86 | ggVennDiagram(x, set_color = c("blue","red","green","purple")) 87 | ``` 88 | 89 | 90 | 91 | `ggVennDiagram` support 2-7 dimension Venn plot. The generated figure is 92 | generally ready for publish. The main function `ggVennDiagram()` will 93 | check how many items in the first parameter and call corresponding 94 | function automatically. 95 | 96 | The parameter `category.names` is set names. And the parameter `label` 97 | can label how many items are included in each parts. 98 | 99 | ``` r 100 | ggVennDiagram(x,category.names = c("Stage 1","Stage 2","Stage 3", "Stage4")) 101 | ``` 102 | 103 | 104 | 105 | ``` r 106 | 107 | ggVennDiagram(x,category.names = c("Stage 1","Stage 2","Stage 3", "Stage4"), label = "none") 108 | ``` 109 | 110 | 111 | 112 | Set `label_alpha = 0` to remove label background. 113 | 114 | ``` r 115 | ggVennDiagram(x, label_alpha=0) 116 | ``` 117 | 118 | 119 | 120 | ## Showing intersection values 121 | 122 | *Note: you need to install the GitHub version to enable these 123 | functions.* 124 | 125 | We implemented the `process_region_data()` to get intersection values. 126 | 127 | ``` r 128 | y <- list( 129 | A = sample(letters, 8), 130 | B = sample(letters, 8), 131 | C = sample(letters, 8), 132 | D = sample(letters, 8) 133 | ) 134 | 135 | process_region_data(Venn(y)) 136 | #> # A tibble: 15 × 4 137 | #> id name item count 138 | #> 139 | #> 1 1 A 3 140 | #> 2 2 B 1 141 | #> 3 3 C 3 142 | #> 4 4 D 0 143 | #> 5 1/2 A/B 0 144 | #> 6 1/3 A/C 1 145 | #> 7 1/4 A/D 2 146 | #> 8 2/3 B/C 1 147 | #> 9 2/4 B/D 3 148 | #> 10 3/4 C/D 1 149 | #> 11 1/2/3 A/B/C 1 150 | #> 12 1/2/4 A/B/D 1 151 | #> 13 1/3/4 A/C/D 0 152 | #> 14 2/3/4 B/C/D 1 153 | #> 15 1/2/3/4 A/B/C/D 0 154 | ``` 155 | 156 | If only several items were included, intersections may also be viewed 157 | interactively by `plotly` method (if you have two many items, this is 158 | useless). 159 | 160 | ``` r 161 | ggVennDiagram(y, show_intersect = TRUE) 162 | ``` 163 | 164 | In web browser or RStudio, you will get: 165 | 166 | 167 | 168 | # Customizing your plot 169 | 170 | There are three components in a Venn plot: 1) the set labels; 2) the 171 | edge of sets; and 3) the filling regions and labels (optional) of each 172 | parts. We separately stored these data in a structured `VennPlotData` 173 | object, in which labels, edges and regions are stored as data frames. 174 | 175 | In general, `ggVennDiagram()` plot a Venn in three steps: 176 | 177 | - get the coordinates of a applicable shape from internal `shapes` 178 | datasets. 179 | - calculate sub regions of sets, including both the shape regions and 180 | sets members, and return a `VennPlotData` object that includes all 181 | necessary definitions. We implement a number of set operations 182 | functions to do this job. 183 | - plot using `ggplot2` functions. 184 | 185 | Please check `vignette("fully-customed", package = "ggVennDiagram")` for 186 | more information. 187 | 188 | # Venn Diagram for more than four sets 189 | 190 | If you have reviewed my codes, you may find it is easy to support Venn 191 | Diagram for more than four sets, as soon as you find a ideal parameter 192 | to generate more circles or ellipses in the plot. The key point is to 193 | let the generated ellipses have exactly one intersection for each 194 | combination. 195 | 196 | ## Venn Diagram of up to seven sets 197 | 198 | From v1.0, `ggVennDiagram` can plot up to seven dimension Venn plot. 199 | Please note that the shapes for this five sets diagram, as well as those 200 | for six and seven sets, are imported from the original package 201 | [`venn`](https://CRAN.R-project.org/package=venn) authored by Adrian 202 | Dușa. 203 | 204 | However, Venn Diagram for more than four sets may be meaningless in some 205 | conditions, as some parts may be omitted in such ellipses. Therefore, it 206 | is only useful in specific conditions. For example, if the set 207 | intersection of all group are extremely large, you may use several 208 | ellipses to draw a “flower” to show that. 209 | 210 | ``` r 211 | x <- list(A=sample(genes,300), 212 | B=sample(genes,525), 213 | C=sample(genes,440), 214 | D=sample(genes,350), 215 | E=sample(genes,200), 216 | F=sample(genes,150), 217 | G=sample(genes,100)) 218 | 219 | # two dimension Venn plot 220 | ggVennDiagram(x[1:2],label = "none") 221 | 222 | # three dimension Venn plot 223 | ggVennDiagram(x[1:3],label = "none") 224 | 225 | # four dimension Venn plot 226 | ggVennDiagram(x[1:4],label = "none") 227 | 228 | # five dimension Venn plot 229 | ggVennDiagram(x[1:5],label = "none") 230 | 231 | # six dimension Venn plot 232 | ggVennDiagram(x[1:6],label = "none") 233 | 234 | # seven dimension Venn plot 235 | ggVennDiagram(x,label = "none") 236 | ``` 237 | 238 | 239 | 240 | ## Native support of upset plot 241 | 242 | From version 1.4.4, `ggVennDiagram` supports unlimited number of sets, 243 | as it can draw a plain upset plot automatically when number of sets is 244 | more than 7. 245 | 246 | ``` r 247 | # add an extra member in list 248 | x$H = sample(genes,500) 249 | ggVennDiagram(x) 250 | #> Warning in ggVennDiagram(x): Only support 2-7 dimension Venn diagram. Will give a plain upset plot instead. 251 | #> Warning: Removed 1 row containing missing values or values outside the scale range (`geom_col()`). 252 | ``` 253 | 254 | 255 | 256 | Upset plot can also be used by setting `force_upset = TRUE`. 257 | 258 | ``` r 259 | ggVennDiagram(x[1:4], force_upset = TRUE, order.set.by = "name", order.intersect.by = "none") 260 | ``` 261 | 262 | 263 | 264 | Since upset plot is consisted with upper panel and lower panel, and left 265 | panel and right panel, the appearance should be adjusted with different 266 | conditions. We provide two parameters, which are `relative_height` and 267 | `relative_width` to do this. 268 | 269 | For example, if we want to give more space to lower panel, just change 270 | the `relative_height` from 3 (the default) to 2. 271 | 272 | ``` r 273 | venn = Venn(x) 274 | plot_upset(venn, nintersects = 30, relative_height = 2, relative_width = 0.3) 275 | ``` 276 | 277 | 278 | 279 | # Reference 280 | 281 | Adrian Dușa (2024) *venn: Draw Venn Diagrams*, R package version 1.12. 282 | . 283 | -------------------------------------------------------------------------------- /R/upset_plot.R: -------------------------------------------------------------------------------- 1 | ## Aims 2 | # 3 | # 1. Reproduce upsetplot 4 | # 2. Expand the function of upsetplot 5 | # 2.1 Allow non-unique intersections 6 | # 2.2 More applicable subplot types (boxplot, points), useful to show subsets properties 7 | 8 | 9 | ## Structures 10 | # 11 | # 1. plot and subplots 12 | # 2. themes 13 | # 3. subsets processing [see regions.R] 14 | 15 | 16 | 17 | ## (PART) Plot 18 | 19 | #' Plot a upset plot 20 | #' 21 | #' This function generate a upset plot by creating a composite plot which contains subplots generated by ggplot2. 22 | #' 23 | #' @param venn a class Venn object 24 | #' @param nintersects number of intersects. If NULL, all intersections will show. 25 | #' @param order.intersect.by 'size', 'name', or "none" 26 | #' @param order.set.by 'size', 'name', or "none" 27 | #' @param relative_height the relative height of top panel in upset plot 28 | #' @param relative_width the relative width of left panel in upset plot 29 | #' @param top.bar.color default is "grey30" 30 | #' @param top.bar.y.label default is NULL 31 | #' @param top.bar.show.numbers default is TRUE 32 | #' @param top.bar.numbers.size text size of numbers 33 | #' @param sets.bar.color default is "grey30" 34 | #' @param sets.bar.show.numbers default is FALSE 35 | #' @param sets.bar.x.label default is "Set Size" 36 | #' @param sets.bar.position the bar plot position of sets ["left"] 37 | #' @param intersection.matrix.color default is "grey30" 38 | #' @param specific whether only include specific items in subsets, default is TRUE. 39 | #' @param ... useless 40 | #' @return an upset plot 41 | #' 42 | #' @export 43 | #' @name upset-plot 44 | #' @examples 45 | #' list = list(A = sample(LETTERS, 20), 46 | #' B = sample(LETTERS, 22), 47 | #' C = sample(LETTERS, 14), 48 | #' D = sample(LETTERS, 30, replace = TRUE)) 49 | #' venn = Venn(list) 50 | #' plot_upset(venn) 51 | #' plot_upset(venn, order.intersect.by = "name") 52 | #' plot_upset(venn, nintersects = 6) 53 | plot_upset = function(venn, 54 | nintersects = NULL, 55 | order.intersect.by = c("size","name","none"), 56 | order.set.by = c("size","name","none"), 57 | relative_height = 3, 58 | relative_width = 0.3, 59 | top.bar.color = "grey30", 60 | top.bar.y.label = NULL, 61 | top.bar.show.numbers = TRUE, 62 | top.bar.numbers.size = 3, 63 | sets.bar.color = "grey30", 64 | sets.bar.show.numbers = FALSE, 65 | sets.bar.x.label = "Set Size", 66 | sets.bar.position = c("left", "right"), 67 | intersection.matrix.color = "grey30", 68 | specific = TRUE, 69 | ...){ 70 | # process arguments 71 | order.intersect.by = match.arg(order.intersect.by) 72 | order.set.by = match.arg(order.set.by) 73 | sets.bar.position = match.arg(sets.bar.position) 74 | 75 | # subplot main 76 | data = process_upset_data(venn, 77 | nintersects = nintersects, 78 | order.intersect.by = order.intersect.by, 79 | order.set.by = order.set.by, 80 | specific = specific) 81 | p_main = upsetplot_main(data$main_data, 82 | intersection.matrix.color = intersection.matrix.color) 83 | 84 | # subplot top 85 | p_top = upsetplot_top(data$top_data, 86 | top.bar.color = top.bar.color, 87 | top.bar.y.label = top.bar.y.label, 88 | top.bar.show.numbers = top.bar.show.numbers, 89 | top.bar.numbers.size = top.bar.numbers.size) 90 | 91 | # subplot left 92 | p_left = upsetplot_left(data$left_data, 93 | sets.bar.color = sets.bar.color, 94 | sets.bar.x.label = sets.bar.x.label, 95 | sets.bar.show.numbers = sets.bar.show.numbers) 96 | 97 | # combine into a plot 98 | pp = aplot::insert_top(p_main, p_top, height = relative_height) 99 | if (sets.bar.position == "right"){ 100 | p_right = p_left + ggplot2::scale_x_continuous() 101 | pp = pp |> 102 | aplot::insert_right(p_right, width = relative_width) 103 | } else { 104 | pp = pp |> 105 | aplot::insert_left(p_left, width = relative_width) 106 | } 107 | 108 | class(pp) = c("upset_plot", class(pp)) 109 | 110 | return(pp) 111 | } 112 | 113 | upsetplot_main = function(data, ...){ 114 | param = list(...) 115 | ggplot2::ggplot(data, aes(.data$id, .data$set)) + 116 | ggplot2::geom_point(size = 4, color = param$intersection.matrix.color, na.rm = FALSE) + 117 | ggplot2::geom_path(aes(group = .data$id), linewidth = 1.5, color = param$intersection.matrix.color, na.rm = FALSE) + 118 | ggplot2::labs(x = "Set Intersection", y = NULL) + 119 | theme_upset_main() 120 | } 121 | 122 | upsetplot_top = function(data, ...){ 123 | param = list(...) 124 | p = ggplot2::ggplot(data, aes(.data$id, .data$size)) + 125 | ggplot2::geom_col(fill = param$top.bar.color) + 126 | ggplot2::labs(x = NULL, y = param$top.bar.y.label) + 127 | scale_y_continuous(expand = ggplot2::expansion(mult = c(0.01, 0.05))) + 128 | theme_upset_top() 129 | if (param$top.bar.show.numbers) { 130 | p = p + ggplot2::geom_text(aes(label = .data$size, 131 | y = .data$size + diff(range(.data$size)) * 0.03), 132 | size = param$top.bar.numbers.size) 133 | } 134 | return(p) 135 | } 136 | 137 | upsetplot_left = function(data, ...){ 138 | param = list(...) 139 | p = ggplot2::ggplot(data, aes(x = .data$size, y = .data$set)) + 140 | ggplot2::geom_col(orientation = "y", fill = param$sets.bar.color) + 141 | ggplot2::scale_y_discrete(position = "right") + 142 | ggplot2::scale_x_reverse() + 143 | ggplot2::labs(x = param$sets.bar.x.label, y = NULL) + 144 | theme_upset_left() 145 | if (param$sets.bar.show.numbers) p = show_numbers_x(p, value = "size") 146 | return(p) 147 | } 148 | 149 | show_numbers_y = function(p, value){ 150 | 151 | } 152 | 153 | show_numbers_x = function(p, value){ 154 | p + ggplot2::geom_text(aes(label = .data[[value]]), 155 | vjust = 0.5) 156 | } 157 | 158 | ## (PART) Theme 159 | 160 | theme_upset_main = function(){ 161 | ggplot2::theme_bw() + 162 | ggplot2::theme( 163 | axis.title.y = element_blank(), 164 | axis.ticks.x.bottom = element_blank(), 165 | axis.text.x.bottom = element_blank(), 166 | # panel.border = element_blank(), 167 | plot.margin = margin(t = -20) 168 | ) 169 | } 170 | 171 | theme_upset_top = function(){ 172 | ggplot2::theme_bw() + 173 | ggplot2::theme( 174 | axis.ticks.x.bottom = element_blank(), 175 | axis.text.x.bottom = element_blank(), 176 | # panel.border = element_blank(), 177 | plot.margin = margin(b = -20, unit = "pt") 178 | ) 179 | } 180 | 181 | theme_upset_left = function(){ 182 | ggplot2::theme_bw() + 183 | ggplot2::theme( 184 | axis.ticks.y = ggplot2::element_blank(), 185 | axis.title.y = ggplot2::element_blank(), 186 | axis.text.y = ggplot2::element_blank(), 187 | panel.border = ggplot2::element_blank(), 188 | panel.grid.major = ggplot2::element_blank(), 189 | plot.margin = margin(r = -60) 190 | ) 191 | } 192 | 193 | 194 | ## (PART) retrieve tidy data from primary subset datasets 195 | 196 | 197 | #' process upset data 198 | #' 199 | #' @inheritParams upset-plot 200 | #' @param specific whether return ONLY specific items for a subset, default is TRUE 201 | #' @details 202 | #' ggVennDiagram, by default, only return the specific subsets of a region. 203 | #' However, sometimes, we want to show all the overlapping items for two or more sets. 204 | #' For example: https://github.com/gaospecial/ggVennDiagram/issues/64 205 | #' Therefore, we add a 'specific' switch to this function. While 'specific = FALSE', 206 | #' the seperator will be changed from "/" to "~", and all the overlapping items 207 | #' will be returned. This feature is useful in plotting upset plot. 208 | #' 209 | #' @return a upsetPlotData object 210 | process_upset_data = function(venn, 211 | nintersects = 30, 212 | order.intersect.by = "size", 213 | order.set.by = "name", 214 | specific = TRUE){ 215 | set_name = venn@names 216 | name_separator = ifelse(specific, "/", "~") 217 | 218 | # region data 219 | data = process_region_data(venn, sep = name_separator, specific = specific) 220 | data$size = data$count 221 | 222 | # top data 223 | top_data = data |> dplyr::select(c('id', 'name', 'item', 'size')) 224 | if (order.intersect.by %in% colnames(top_data)) { 225 | top_data = dplyr::mutate(top_data, 226 | id = forcats::fct_reorder(.data$id, .data[[order.intersect.by]], .desc = TRUE)) 227 | } else { 228 | top_data$id = forcats::as_factor(top_data$id) 229 | } 230 | 231 | # left data 232 | left_data = dplyr::tibble(set = set_name, 233 | name = set_name, 234 | size = lengths(venn@sets)) 235 | if (order.set.by %in% colnames(left_data)) { 236 | left_data = dplyr::mutate(left_data, 237 | set = forcats::fct_reorder(.data$set, .data[[order.set.by]], .desc = TRUE)) 238 | } else { 239 | left_data$set = forcats::as_factor(left_data$set) |> forcats::fct_rev() 240 | } 241 | 242 | # main data 243 | main_data = data |> dplyr::select(c("id", "name", "size")) 244 | main_data$set_id = main_data$id 245 | main_data = separate_longer_delim(main_data, "set_id", delim = name_separator) 246 | main_data$set = factor(set_name[as.integer(main_data$set_id)], 247 | levels = levels(left_data$set)) 248 | main_data$id = factor(main_data$id, levels = levels(top_data$id)) 249 | 250 | # filter intersections 251 | if (is.numeric(nintersects)) { 252 | keep_id = utils::head(levels(top_data$id), nintersects) 253 | main_data = main_data |> dplyr::filter(.data$id %in% keep_id) 254 | top_data = top_data |> dplyr::filter(.data$id %in% keep_id) 255 | } 256 | 257 | # return result as a list 258 | ret = list(top_data = top_data, 259 | left_data = left_data, 260 | main_data = main_data) 261 | class(ret) = 'upsetPlotData' 262 | return(ret) 263 | } 264 | 265 | 266 | #' S3 method for `upsetPlotData` 267 | #' 268 | #' @param x a upsetPlotData object 269 | #' @param ... useless 270 | #' 271 | #' @method print upsetPlotData 272 | #' @docType methods 273 | #' @name print 274 | #' @rdname print 275 | #' @md 276 | #' @export 277 | print.upsetPlotData = function(x, ...){ 278 | cat(sprintf("Class upsetPlotData.\n")) 279 | cat(sprintf(" Type: list; No. slots: %d; Slot names: %s.\n", length(x), paste(names(x), collapse = ", "))) 280 | cat(sprintf(" To view the data interactively, use 'obj[[\"slotName\"]]'.\n")) 281 | } 282 | 283 | 284 | 285 | 286 | #' Implement of `tidyr::separate_longer_delim` 287 | #' 288 | #' @param df a data.frame 289 | #' @param col column 290 | #' @param delim delimeter 291 | #' 292 | #' @return a data.frame 293 | #' @md 294 | separate_longer_delim <- function(df, col, delim) { 295 | # 将要拆分的列按照分隔符拆分成字符向量 296 | split_values <- strsplit(df[[col]], delim) 297 | 298 | # 扩展数据框 299 | result <- df[rep(seq_len(nrow(df)), times = lengths(split_values)), ] 300 | 301 | # 将拆分后的值填充到新的列中 302 | result[[col]] <- unlist(split_values) 303 | 304 | return(result) 305 | } 306 | -------------------------------------------------------------------------------- /less-dependency.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Update of ggVennDiagram 1.5" 3 | output: word_document 4 | --- 5 | 6 | ```{r, include = FALSE} 7 | knitr::opts_chunk$set( 8 | collapse = TRUE, 9 | comment = "#>", 10 | fig.width = 7 11 | ) 12 | ``` 13 | 14 | ```{r setup} 15 | devtools::load_all() 16 | library(dplyr) 17 | library(pak) 18 | ``` 19 | 20 | ```{r} 21 | genes <- paste("gene",1:1000,sep="") 22 | set.seed(20231214) 23 | x <- list(A=sample(genes,300), 24 | B=sample(genes,525), 25 | C=sample(genes,440), 26 | D=sample(genes,350), 27 | E=sample(genes,400), 28 | F=sample(genes,300), 29 | G=sample(genes,200), 30 | H=sample(genes,450)) 31 | ``` 32 | 33 | 34 | ## Less dependency 35 | 36 | `ggVennDiagram` has a large package dependencies. This is because we build this package standing on the shoulder of those who came before us. 37 | 38 | ```{r} 39 | dependency = c( 40 | "sf", 41 | "ggplot2", 42 | "dplyr", 43 | "stringr", 44 | "magrittr", 45 | "methods", 46 | "purrr", 47 | "tibble", 48 | "plotly", 49 | "RVenn", 50 | "tidyr", 51 | "venn" 52 | ) 53 | ``` 54 | 55 | Although we only import ten packages in the development, the dependence tree is huge. 56 | 57 | ```{r} 58 | deps = pak::pkg_deps_tree("gaospecial/ggVennDiagram@V1.1") 59 | ``` 60 | ```{r} 61 | deps |> select(package, filesize) |> 62 | arrange(desc(filesize)) 63 | ``` 64 | 65 | 66 | ### Remove sf dependency 67 | 68 | Among them, `sf` is the heaviest package that `ggVennDiagram` depend on. 69 | 70 | ```{r} 71 | pak_dep = deps |> 72 | select(package, sysreqs, filesize) |> 73 | arrange(desc(filesize)) |> 74 | filter(package %in% dependency) 75 | pak_dep 76 | ``` 77 | 78 | 79 | ```{r eval=FALSE} 80 | pak_dep |> 81 | write.csv("deps.csv") 82 | ``` 83 | 84 | 85 | Package `sf` not only has the largest size, but also depends on several system packages, such as `GDAL`, `GEOS`, `PROJ`, and so on. Furthermore, two of the `sf`-dependent packages, `s2` and `units` also have system requirements, especially `units`, whose system dependence `udunits-2` is an additional one that usually not installed by most of the `ggVennDiagram` users. 86 | 87 | ```{r} 88 | deps_sf = pak::pkg_deps("sf") 89 | deps |> filter(package %in% deps_sf$package, sysreqs != "") |> 90 | select(package, sysreqs, filesize) 91 | ``` 92 | 93 | However, `sf` is a necessary for the full functions of `ggVennDiagram` in shape generation. So it is difficult to remove it. Therefore, we decided to move the shape generation functions to a new package, namely `shapeMageR`. And only import this package as a "suggestion" in new version of `ggVennDiagram`. 94 | 95 | ### Other dependencies 96 | 97 | Besides, several other packages are removed from dependency list after considerations. 98 | 99 | ```{r} 100 | deps |> 101 | select(package, sysreqs, filesize) |> 102 | filter(!package %in% pak::pkg_deps("sf")$package, 103 | !package %in% pak::pkg_deps("ggplot2")$package) |> 104 | arrange(desc(filesize)) 105 | ``` 106 | 107 | |package | reason | 108 | |-------- | ------------------------------------------| 109 | | `plotly` | Not the main feature, many dependencies | 110 | | `RVenn` | Easy to replace | 111 | 112 | 113 | - [RVenn](https://cran.r-project.org/web/packages/RVenn/vignettes/vignette.html) 114 | 115 | The author of RVenn agreed to reuse his code and is open for join in the further development of ggVennDiagram. I will also add him as a co-author of the new manuscript. 116 | 117 | ## New dependency after version 1.4.9 118 | 119 | ### Short dependency tree 120 | 121 | ```{r} 122 | deps_new = pak::pkg_deps_tree(".") 123 | ``` 124 | 125 | 126 | ```{r} 127 | dependency_new = c( 128 | "ggplot2", 129 | "dplyr", 130 | "methods", 131 | "tibble", 132 | "aplot", 133 | "forcats", 134 | "venn", 135 | "yulab.utils") 136 | primary_deps = deps_new |> 137 | select(package, sysreqs, filesize) |> 138 | arrange(desc(filesize)) |> 139 | filter(package %in% dependency_new) 140 | primary_deps 141 | # write.csv(primary_deps, file = "deps_current.csv") 142 | ``` 143 | 144 | 145 | ### Comparison of dependency 146 | 147 | ```{r} 148 | #' Report package dependency 149 | #' 150 | #' @param pkg 151 | #' @param size_cutoff 152 | #' @param n 153 | #' @param exclude 154 | #' 155 | #' @return 156 | #' @export 157 | #' 158 | #' @examples 159 | #' report_package_dependency("ggplot2") 160 | report_package_dependency = function(pkg, size_cutoff = 2^20, n = 3, exclude = NULL){ 161 | # find deps of excluding package 162 | if (!is.null(exclude)){ 163 | if (is.vector(exclude) & length(exclude) > 1){ 164 | exclude = lapply(exclude, function(x){ 165 | pak::pkg_deps(x) |> 166 | dplyr::pull(package) 167 | }) |> 168 | unlist() |> 169 | unique() 170 | } else { 171 | exclude = pak::pkg_deps(exclude) |> pull(package) 172 | } 173 | } 174 | 175 | # find deps and format output 176 | deps = pak::pkg_deps(pkg) |> 177 | dplyr::filter(!is.na(ref), !(package %in% exclude)) |> 178 | dplyr::arrange(desc(filesize)) |> 179 | dplyr::rowwise() |> 180 | dplyr::mutate(package_size = paste0(package, " (", scales::number_bytes(filesize, units = "si"), ")")) 181 | 182 | # generating report 183 | tot_filesize = sum(deps$filesize, na.rm = TRUE) |> scales::number_bytes(units = "si") 184 | big_pkg = deps |> dplyr::filter(filesize > size_cutoff) 185 | sys_pkg = deps |> dplyr::filter(sysreqs != "", !is.na(sysreqs), 186 | !package %in% big_pkg$package) 187 | glue::glue("Summary of '{pkg}' Dependency", 188 | "", 189 | " Total size: {tot_filesize}; {nrow(deps)} package(s), and {nrow(sys_pkg)} system requirement(s).", 190 | " Package(s) larger than {scales::number_bytes(size_cutoff, units = 'si')} ({nrow(big_pkg)}): {paste(head(big_pkg$package_size,n), collapse = ', ')}{ifelse(nrow(big_pkg)>n, '...', '.')}", 191 | " Additional system dependency ({nrow(sys_pkg)}): {paste(head(sys_pkg$package,n), collapse = ', ')}{ifelse(nrow(sys_pkg)>n, '...', '.')}", 192 | .sep = "\n") 193 | } 194 | ``` 195 | 196 | 197 | ```{r} 198 | for (tag in c("V0.5.0","V1.0.7","V1.1","V1.2","V1.2.2","V1.4.9")){ 199 | report_package_dependency(paste0("gaospecial/ggVennDiagram@", tag)) |> print() 200 | } 201 | ``` 202 | 203 | 204 | ```{r} 205 | report_package_dependency(".") 206 | ``` 207 | 208 | ```{r} 209 | report_package_dependency(".", exclude = c("ggplot2","dplyr")) 210 | ``` 211 | 212 | ### Current depdency 213 | 214 | ```{r} 215 | pkg_deps_tree(".") 216 | ``` 217 | 218 | ## More optimizations 219 | 220 | ### The introduction of `shapeMageR` package 221 | 222 | `shapeMageR` is implemented to deal with the shape generation for plotting complex geometries in `ggVennDiagram`. It's named after "shape + mage + R". All the related shape generation functions used in `ggVennDiagram` are transferred to the new `shapeMageR` package. 223 | 224 | - Shape Generation 225 | - Circle 226 | - Ellipse 227 | - Triangle 228 | - Rectangle 229 | - Line 230 | - Dot 231 | - Geometry Processing 232 | - diff 233 | - union 234 | - discern 235 | - overlap 236 | - Shape Transformation 237 | - sf2polygon 238 | - polygon2sf 239 | - Misc 240 | - shape reading 241 | 242 | 243 | 244 | ## Ready-to-use new shapes 245 | 246 | 247 | 248 | ![](https://vnote-1251564393.cos.ap-chengdu.myqcloud.com/20231112002209.png) 249 | 250 | ![](https://vnote-1251564393.cos.ap-chengdu.myqcloud.com/20231112002411.png) 251 | 252 | ## Native support for Upset plot 253 | 254 | As been stated in our previous publication, Venn Diagram is not suitable for analyzing more than seven sets. In that case we recommend the Upset plot as an alternative method, which is supported by `UpsetR` in R platform. We add native support for Upset plot. 255 | 256 | This function will be provided on base of aplot. 257 | 258 | ```{r} 259 | p1 = ggVennDiagram(x[1:5], label="none", set_color = rainbow(5)) + scale_fill_distiller(palette = "Reds", direction = 1) 260 | p2 = ggVennDiagram(x[1:5], force_upset = TRUE, order.intersect.by = "none", order.set.by = "none", nintersects = 15) 261 | 262 | aplot::plot_list(p1,p2, widths = c(0.6, 1)) 263 | ``` 264 | 265 | 266 | ```{r} 267 | ggVennDiagram(x, nintersects = 30, order.set.by = "none", order.intersect.by = "size") 268 | ``` 269 | 270 | 271 | 272 | 273 | **Read more**: 274 | 275 | - [about Upset](https://upset.app/) 276 | 277 | ## Optimization of default settings 278 | 279 | **Transparent background of labels** 280 | 281 | 282 | **Gray line of region borders** 283 | 284 | 285 | **Region fill colors pallete** 286 | 287 | 288 | ## Access to classes 289 | 290 | ```{r} 291 | set.seed(20231225) 292 | y = list( 293 | A = sample(letters, 8) |> sort(), 294 | B = sample(letters, 8) |> sort(), 295 | C = sample(letters, 8) |> sort(), 296 | D = sample(letters, 8) |> sort()) 297 | 298 | # view the list 299 | y 300 | ``` 301 | 302 | ### Access to subset items 303 | 304 | To view subset itmes interactively, set `show_intersect = TRUE`. 305 | 306 | ```{r} 307 | if (knitr::is_html_output()) ggVennDiagram(y, show_intersect = TRUE, set_color = "black") 308 | ``` 309 | 310 | 311 | ```{r} 312 | venn_y = Venn(y) 313 | 314 | venn_y 315 | ``` 316 | 317 | 318 | 319 | ```{r} 320 | # find the overlaping members of two or more sets 321 | overlap(venn_y, 1:2) # members in both the first two sets 322 | overlap(venn_y) # members in all the sets 323 | 324 | # find the different members between sets and set unions 325 | discern(venn_y, 1) # members in set 1, but not in the resting sets 326 | discern(venn_y, c("A","B"), 3) # members in set A & B, but not in the 3rd set 327 | 328 | # find the specific members in one or more sets 329 | discern_overlap(venn_y, 1) # specific items in set 1 330 | discern_overlap(venn_y, 1:2) # specific items in set 1 and set 2 331 | ``` 332 | 333 | 334 | ### Access to plot data 335 | 336 | ```{r} 337 | venn_plot_data = process_data(venn_y) 338 | 339 | # summary of VennPlotData object 340 | venn_plot_data 341 | ``` 342 | 343 | Sets and labels 344 | 345 | ```{r} 346 | # get the set data 347 | venn_set(venn_plot_data) 348 | 349 | # get subsets, i.e., regions 350 | venn_region(venn_plot_data) 351 | ``` 352 | 353 | Polygons. 354 | 355 | ```{r} 356 | # get set edge 357 | venn_setedge(venn_plot_data) 358 | 359 | # get region edge 360 | venn_regionedge(venn_plot_data) 361 | ``` 362 | 363 | ```{r} 364 | df = venn_setedge(venn_plot_data) 365 | ggplot(df, aes(X, Y, group = id, color = id)) + 366 | geom_path() + 367 | coord_equal() 368 | ``` 369 | ```{r} 370 | df = venn_regionedge(venn_plot_data) 371 | ggplot(df, aes(X, Y, group = id, fill = count)) + 372 | geom_polygon() + 373 | geom_path(color = "white", size = 5) + 374 | scale_fill_distiller(palette = "Reds") + 375 | coord_equal() + 376 | theme_void() 377 | ``` 378 | 379 | 380 | ## Unified coordinations 381 | 382 | Transforming coordination. 383 | 384 | ## Work with TBtools 385 | 386 | Provide an official TBtools plugin. 387 | 388 | TBtools refers to a bioinformatics software tool designed for the analysis and visualization of genomic data. TBtools is often used in genomics and molecular biology research to handle and analyze large-scale biological data. In ggVennDiagram 1.5, we provided an official TBtools plugin in the plugin store of TBtools. 389 | 390 | 391 | ## Provided as Shiny app 392 | 393 | Shiny provide a web interface to access the core functions of ggVennDiagram. For those light users, it is not a necessary to install ggVennDiagram, as the Shiny app would give publication quality figures with optimized parameters. In addition to bitmap figures (png/jpg/tiff), the Shiny app can also export figure as vector graphics such as PDF, and PPTX. Therefore, the figures can be substantially polished with hands-on software by users. 394 | 395 | ```{r eval=FALSE} 396 | launch_app() 397 | ``` 398 | 399 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU General Public License 2 | ========================== 3 | 4 | _Version 3, 29 June 2007_ 5 | _Copyright 2007 Free Software Foundation, Inc. <>_ 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license 8 | document, but changing it is not allowed. 9 | 10 | ## Preamble 11 | 12 | The GNU General Public License is a free, copyleft license for software and other 13 | kinds of works. 14 | 15 | The licenses for most software and other practical works are designed to take away 16 | your freedom to share and change the works. By contrast, the GNU General Public 17 | License is intended to guarantee your freedom to share and change all versions of a 18 | program--to make sure it remains free software for all its users. We, the Free 19 | Software Foundation, use the GNU General Public License for most of our software; it 20 | applies also to any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not price. Our General 24 | Public Licenses are designed to make sure that you have the freedom to distribute 25 | copies of free software (and charge for them if you wish), that you receive source 26 | code or can get it if you want it, that you can change the software or use pieces of 27 | it in new free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you these rights or 30 | asking you to surrender the rights. Therefore, you have certain responsibilities if 31 | you distribute copies of the software, or if you modify it: responsibilities to 32 | respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether gratis or for a fee, 35 | you must pass on to the recipients the same freedoms that you received. You must make 36 | sure that they, too, receive or can get the source code. And you must show them these 37 | terms so they know their rights. 38 | 39 | Developers that use the GNU GPL protect your rights with two steps: **(1)** assert 40 | copyright on the software, and **(2)** offer you this License giving you legal permission 41 | to copy, distribute and/or modify it. 42 | 43 | For the developers' and authors' protection, the GPL clearly explains that there is 44 | no warranty for this free software. For both users' and authors' sake, the GPL 45 | requires that modified versions be marked as changed, so that their problems will not 46 | be attributed erroneously to authors of previous versions. 47 | 48 | Some devices are designed to deny users access to install or run modified versions of 49 | the software inside them, although the manufacturer can do so. This is fundamentally 50 | incompatible with the aim of protecting users' freedom to change the software. The 51 | systematic pattern of such abuse occurs in the area of products for individuals to 52 | use, which is precisely where it is most unacceptable. Therefore, we have designed 53 | this version of the GPL to prohibit the practice for those products. If such problems 54 | arise substantially in other domains, we stand ready to extend this provision to 55 | those domains in future versions of the GPL, as needed to protect the freedom of 56 | users. 57 | 58 | Finally, every program is threatened constantly by software patents. States should 59 | not allow patents to restrict development and use of software on general-purpose 60 | computers, but in those that do, we wish to avoid the special danger that patents 61 | applied to a free program could make it effectively proprietary. To prevent this, the 62 | GPL assures that patents cannot be used to render the program non-free. 63 | 64 | The precise terms and conditions for copying, distribution and modification follow. 65 | 66 | ## TERMS AND CONDITIONS 67 | 68 | ### 0. Definitions 69 | 70 | “This License” refers to version 3 of the GNU General Public License. 71 | 72 | “Copyright” also means copyright-like laws that apply to other kinds of 73 | works, such as semiconductor masks. 74 | 75 | “The Program” refers to any copyrightable work licensed under this 76 | License. Each licensee is addressed as “you”. “Licensees” and 77 | “recipients” may be individuals or organizations. 78 | 79 | To “modify” a work means to copy from or adapt all or part of the work in 80 | a fashion requiring copyright permission, other than the making of an exact copy. The 81 | resulting work is called a “modified version” of the earlier work or a 82 | work “based on” the earlier work. 83 | 84 | A “covered work” means either the unmodified Program or a work based on 85 | the Program. 86 | 87 | To “propagate” a work means to do anything with it that, without 88 | permission, would make you directly or secondarily liable for infringement under 89 | applicable copyright law, except executing it on a computer or modifying a private 90 | copy. Propagation includes copying, distribution (with or without modification), 91 | making available to the public, and in some countries other activities as well. 92 | 93 | To “convey” a work means any kind of propagation that enables other 94 | parties to make or receive copies. Mere interaction with a user through a computer 95 | network, with no transfer of a copy, is not conveying. 96 | 97 | An interactive user interface displays “Appropriate Legal Notices” to the 98 | extent that it includes a convenient and prominently visible feature that **(1)** 99 | displays an appropriate copyright notice, and **(2)** tells the user that there is no 100 | warranty for the work (except to the extent that warranties are provided), that 101 | licensees may convey the work under this License, and how to view a copy of this 102 | License. If the interface presents a list of user commands or options, such as a 103 | menu, a prominent item in the list meets this criterion. 104 | 105 | ### 1. Source Code 106 | 107 | The “source code” for a work means the preferred form of the work for 108 | making modifications to it. “Object code” means any non-source form of a 109 | work. 110 | 111 | A “Standard Interface” means an interface that either is an official 112 | standard defined by a recognized standards body, or, in the case of interfaces 113 | specified for a particular programming language, one that is widely used among 114 | developers working in that language. 115 | 116 | The “System Libraries” of an executable work include anything, other than 117 | the work as a whole, that **(a)** is included in the normal form of packaging a Major 118 | Component, but which is not part of that Major Component, and **(b)** serves only to 119 | enable use of the work with that Major Component, or to implement a Standard 120 | Interface for which an implementation is available to the public in source code form. 121 | A “Major Component”, in this context, means a major essential component 122 | (kernel, window system, and so on) of the specific operating system (if any) on which 123 | the executable work runs, or a compiler used to produce the work, or an object code 124 | interpreter used to run it. 125 | 126 | The “Corresponding Source” for a work in object code form means all the 127 | source code needed to generate, install, and (for an executable work) run the object 128 | code and to modify the work, including scripts to control those activities. However, 129 | it does not include the work's System Libraries, or general-purpose tools or 130 | generally available free programs which are used unmodified in performing those 131 | activities but which are not part of the work. For example, Corresponding Source 132 | includes interface definition files associated with source files for the work, and 133 | the source code for shared libraries and dynamically linked subprograms that the work 134 | is specifically designed to require, such as by intimate data communication or 135 | control flow between those subprograms and other parts of the work. 136 | 137 | The Corresponding Source need not include anything that users can regenerate 138 | automatically from other parts of the Corresponding Source. 139 | 140 | The Corresponding Source for a work in source code form is that same work. 141 | 142 | ### 2. Basic Permissions 143 | 144 | All rights granted under this License are granted for the term of copyright on the 145 | Program, and are irrevocable provided the stated conditions are met. This License 146 | explicitly affirms your unlimited permission to run the unmodified Program. The 147 | output from running a covered work is covered by this License only if the output, 148 | given its content, constitutes a covered work. This License acknowledges your rights 149 | of fair use or other equivalent, as provided by copyright law. 150 | 151 | You may make, run and propagate covered works that you do not convey, without 152 | conditions so long as your license otherwise remains in force. You may convey covered 153 | works to others for the sole purpose of having them make modifications exclusively 154 | for you, or provide you with facilities for running those works, provided that you 155 | comply with the terms of this License in conveying all material for which you do not 156 | control copyright. Those thus making or running the covered works for you must do so 157 | exclusively on your behalf, under your direction and control, on terms that prohibit 158 | them from making any copies of your copyrighted material outside their relationship 159 | with you. 160 | 161 | Conveying under any other circumstances is permitted solely under the conditions 162 | stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 163 | 164 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law 165 | 166 | No covered work shall be deemed part of an effective technological measure under any 167 | applicable law fulfilling obligations under article 11 of the WIPO copyright treaty 168 | adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention 169 | of such measures. 170 | 171 | When you convey a covered work, you waive any legal power to forbid circumvention of 172 | technological measures to the extent such circumvention is effected by exercising 173 | rights under this License with respect to the covered work, and you disclaim any 174 | intention to limit operation or modification of the work as a means of enforcing, 175 | against the work's users, your or third parties' legal rights to forbid circumvention 176 | of technological measures. 177 | 178 | ### 4. Conveying Verbatim Copies 179 | 180 | You may convey verbatim copies of the Program's source code as you receive it, in any 181 | medium, provided that you conspicuously and appropriately publish on each copy an 182 | appropriate copyright notice; keep intact all notices stating that this License and 183 | any non-permissive terms added in accord with section 7 apply to the code; keep 184 | intact all notices of the absence of any warranty; and give all recipients a copy of 185 | this License along with the Program. 186 | 187 | You may charge any price or no price for each copy that you convey, and you may offer 188 | support or warranty protection for a fee. 189 | 190 | ### 5. Conveying Modified Source Versions 191 | 192 | You may convey a work based on the Program, or the modifications to produce it from 193 | the Program, in the form of source code under the terms of section 4, provided that 194 | you also meet all of these conditions: 195 | 196 | * **a)** The work must carry prominent notices stating that you modified it, and giving a 197 | relevant date. 198 | * **b)** The work must carry prominent notices stating that it is released under this 199 | License and any conditions added under section 7. This requirement modifies the 200 | requirement in section 4 to “keep intact all notices”. 201 | * **c)** You must license the entire work, as a whole, under this License to anyone who 202 | comes into possession of a copy. This License will therefore apply, along with any 203 | applicable section 7 additional terms, to the whole of the work, and all its parts, 204 | regardless of how they are packaged. This License gives no permission to license the 205 | work in any other way, but it does not invalidate such permission if you have 206 | separately received it. 207 | * **d)** If the work has interactive user interfaces, each must display Appropriate Legal 208 | Notices; however, if the Program has interactive interfaces that do not display 209 | Appropriate Legal Notices, your work need not make them do so. 210 | 211 | A compilation of a covered work with other separate and independent works, which are 212 | not by their nature extensions of the covered work, and which are not combined with 213 | it such as to form a larger program, in or on a volume of a storage or distribution 214 | medium, is called an “aggregate” if the compilation and its resulting 215 | copyright are not used to limit the access or legal rights of the compilation's users 216 | beyond what the individual works permit. Inclusion of a covered work in an aggregate 217 | does not cause this License to apply to the other parts of the aggregate. 218 | 219 | ### 6. Conveying Non-Source Forms 220 | 221 | You may convey a covered work in object code form under the terms of sections 4 and 222 | 5, provided that you also convey the machine-readable Corresponding Source under the 223 | terms of this License, in one of these ways: 224 | 225 | * **a)** Convey the object code in, or embodied in, a physical product (including a 226 | physical distribution medium), accompanied by the Corresponding Source fixed on a 227 | durable physical medium customarily used for software interchange. 228 | * **b)** Convey the object code in, or embodied in, a physical product (including a 229 | physical distribution medium), accompanied by a written offer, valid for at least 230 | three years and valid for as long as you offer spare parts or customer support for 231 | that product model, to give anyone who possesses the object code either **(1)** a copy of 232 | the Corresponding Source for all the software in the product that is covered by this 233 | License, on a durable physical medium customarily used for software interchange, for 234 | a price no more than your reasonable cost of physically performing this conveying of 235 | source, or **(2)** access to copy the Corresponding Source from a network server at no 236 | charge. 237 | * **c)** Convey individual copies of the object code with a copy of the written offer to 238 | provide the Corresponding Source. This alternative is allowed only occasionally and 239 | noncommercially, and only if you received the object code with such an offer, in 240 | accord with subsection 6b. 241 | * **d)** Convey the object code by offering access from a designated place (gratis or for 242 | a charge), and offer equivalent access to the Corresponding Source in the same way 243 | through the same place at no further charge. You need not require recipients to copy 244 | the Corresponding Source along with the object code. If the place to copy the object 245 | code is a network server, the Corresponding Source may be on a different server 246 | (operated by you or a third party) that supports equivalent copying facilities, 247 | provided you maintain clear directions next to the object code saying where to find 248 | the Corresponding Source. Regardless of what server hosts the Corresponding Source, 249 | you remain obligated to ensure that it is available for as long as needed to satisfy 250 | these requirements. 251 | * **e)** Convey the object code using peer-to-peer transmission, provided you inform 252 | other peers where the object code and Corresponding Source of the work are being 253 | offered to the general public at no charge under subsection 6d. 254 | 255 | A separable portion of the object code, whose source code is excluded from the 256 | Corresponding Source as a System Library, need not be included in conveying the 257 | object code work. 258 | 259 | A “User Product” is either **(1)** a “consumer product”, which 260 | means any tangible personal property which is normally used for personal, family, or 261 | household purposes, or **(2)** anything designed or sold for incorporation into a 262 | dwelling. In determining whether a product is a consumer product, doubtful cases 263 | shall be resolved in favor of coverage. For a particular product received by a 264 | particular user, “normally used” refers to a typical or common use of 265 | that class of product, regardless of the status of the particular user or of the way 266 | in which the particular user actually uses, or expects or is expected to use, the 267 | product. A product is a consumer product regardless of whether the product has 268 | substantial commercial, industrial or non-consumer uses, unless such uses represent 269 | the only significant mode of use of the product. 270 | 271 | “Installation Information” for a User Product means any methods, 272 | procedures, authorization keys, or other information required to install and execute 273 | modified versions of a covered work in that User Product from a modified version of 274 | its Corresponding Source. The information must suffice to ensure that the continued 275 | functioning of the modified object code is in no case prevented or interfered with 276 | solely because modification has been made. 277 | 278 | If you convey an object code work under this section in, or with, or specifically for 279 | use in, a User Product, and the conveying occurs as part of a transaction in which 280 | the right of possession and use of the User Product is transferred to the recipient 281 | in perpetuity or for a fixed term (regardless of how the transaction is 282 | characterized), the Corresponding Source conveyed under this section must be 283 | accompanied by the Installation Information. But this requirement does not apply if 284 | neither you nor any third party retains the ability to install modified object code 285 | on the User Product (for example, the work has been installed in ROM). 286 | 287 | The requirement to provide Installation Information does not include a requirement to 288 | continue to provide support service, warranty, or updates for a work that has been 289 | modified or installed by the recipient, or for the User Product in which it has been 290 | modified or installed. Access to a network may be denied when the modification itself 291 | materially and adversely affects the operation of the network or violates the rules 292 | and protocols for communication across the network. 293 | 294 | Corresponding Source conveyed, and Installation Information provided, in accord with 295 | this section must be in a format that is publicly documented (and with an 296 | implementation available to the public in source code form), and must require no 297 | special password or key for unpacking, reading or copying. 298 | 299 | ### 7. Additional Terms 300 | 301 | “Additional permissions” are terms that supplement the terms of this 302 | License by making exceptions from one or more of its conditions. Additional 303 | permissions that are applicable to the entire Program shall be treated as though they 304 | were included in this License, to the extent that they are valid under applicable 305 | law. If additional permissions apply only to part of the Program, that part may be 306 | used separately under those permissions, but the entire Program remains governed by 307 | this License without regard to the additional permissions. 308 | 309 | When you convey a copy of a covered work, you may at your option remove any 310 | additional permissions from that copy, or from any part of it. (Additional 311 | permissions may be written to require their own removal in certain cases when you 312 | modify the work.) You may place additional permissions on material, added by you to a 313 | covered work, for which you have or can give appropriate copyright permission. 314 | 315 | Notwithstanding any other provision of this License, for material you add to a 316 | covered work, you may (if authorized by the copyright holders of that material) 317 | supplement the terms of this License with terms: 318 | 319 | * **a)** Disclaiming warranty or limiting liability differently from the terms of 320 | sections 15 and 16 of this License; or 321 | * **b)** Requiring preservation of specified reasonable legal notices or author 322 | attributions in that material or in the Appropriate Legal Notices displayed by works 323 | containing it; or 324 | * **c)** Prohibiting misrepresentation of the origin of that material, or requiring that 325 | modified versions of such material be marked in reasonable ways as different from the 326 | original version; or 327 | * **d)** Limiting the use for publicity purposes of names of licensors or authors of the 328 | material; or 329 | * **e)** Declining to grant rights under trademark law for use of some trade names, 330 | trademarks, or service marks; or 331 | * **f)** Requiring indemnification of licensors and authors of that material by anyone 332 | who conveys the material (or modified versions of it) with contractual assumptions of 333 | liability to the recipient, for any liability that these contractual assumptions 334 | directly impose on those licensors and authors. 335 | 336 | All other non-permissive additional terms are considered “further 337 | restrictions” within the meaning of section 10. If the Program as you received 338 | it, or any part of it, contains a notice stating that it is governed by this License 339 | along with a term that is a further restriction, you may remove that term. If a 340 | license document contains a further restriction but permits relicensing or conveying 341 | under this License, you may add to a covered work material governed by the terms of 342 | that license document, provided that the further restriction does not survive such 343 | relicensing or conveying. 344 | 345 | If you add terms to a covered work in accord with this section, you must place, in 346 | the relevant source files, a statement of the additional terms that apply to those 347 | files, or a notice indicating where to find the applicable terms. 348 | 349 | Additional terms, permissive or non-permissive, may be stated in the form of a 350 | separately written license, or stated as exceptions; the above requirements apply 351 | either way. 352 | 353 | ### 8. Termination 354 | 355 | You may not propagate or modify a covered work except as expressly provided under 356 | this License. Any attempt otherwise to propagate or modify it is void, and will 357 | automatically terminate your rights under this License (including any patent licenses 358 | granted under the third paragraph of section 11). 359 | 360 | However, if you cease all violation of this License, then your license from a 361 | particular copyright holder is reinstated **(a)** provisionally, unless and until the 362 | copyright holder explicitly and finally terminates your license, and **(b)** permanently, 363 | if the copyright holder fails to notify you of the violation by some reasonable means 364 | prior to 60 days after the cessation. 365 | 366 | Moreover, your license from a particular copyright holder is reinstated permanently 367 | if the copyright holder notifies you of the violation by some reasonable means, this 368 | is the first time you have received notice of violation of this License (for any 369 | work) from that copyright holder, and you cure the violation prior to 30 days after 370 | your receipt of the notice. 371 | 372 | Termination of your rights under this section does not terminate the licenses of 373 | parties who have received copies or rights from you under this License. If your 374 | rights have been terminated and not permanently reinstated, you do not qualify to 375 | receive new licenses for the same material under section 10. 376 | 377 | ### 9. Acceptance Not Required for Having Copies 378 | 379 | You are not required to accept this License in order to receive or run a copy of the 380 | Program. Ancillary propagation of a covered work occurring solely as a consequence of 381 | using peer-to-peer transmission to receive a copy likewise does not require 382 | acceptance. However, nothing other than this License grants you permission to 383 | propagate or modify any covered work. These actions infringe copyright if you do not 384 | accept this License. Therefore, by modifying or propagating a covered work, you 385 | indicate your acceptance of this License to do so. 386 | 387 | ### 10. Automatic Licensing of Downstream Recipients 388 | 389 | Each time you convey a covered work, the recipient automatically receives a license 390 | from the original licensors, to run, modify and propagate that work, subject to this 391 | License. You are not responsible for enforcing compliance by third parties with this 392 | License. 393 | 394 | An “entity transaction” is a transaction transferring control of an 395 | organization, or substantially all assets of one, or subdividing an organization, or 396 | merging organizations. If propagation of a covered work results from an entity 397 | transaction, each party to that transaction who receives a copy of the work also 398 | receives whatever licenses to the work the party's predecessor in interest had or 399 | could give under the previous paragraph, plus a right to possession of the 400 | Corresponding Source of the work from the predecessor in interest, if the predecessor 401 | has it or can get it with reasonable efforts. 402 | 403 | You may not impose any further restrictions on the exercise of the rights granted or 404 | affirmed under this License. For example, you may not impose a license fee, royalty, 405 | or other charge for exercise of rights granted under this License, and you may not 406 | initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging 407 | that any patent claim is infringed by making, using, selling, offering for sale, or 408 | importing the Program or any portion of it. 409 | 410 | ### 11. Patents 411 | 412 | A “contributor” is a copyright holder who authorizes use under this 413 | License of the Program or a work on which the Program is based. The work thus 414 | licensed is called the contributor's “contributor version”. 415 | 416 | A contributor's “essential patent claims” are all patent claims owned or 417 | controlled by the contributor, whether already acquired or hereafter acquired, that 418 | would be infringed by some manner, permitted by this License, of making, using, or 419 | selling its contributor version, but do not include claims that would be infringed 420 | only as a consequence of further modification of the contributor version. For 421 | purposes of this definition, “control” includes the right to grant patent 422 | sublicenses in a manner consistent with the requirements of this License. 423 | 424 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license 425 | under the contributor's essential patent claims, to make, use, sell, offer for sale, 426 | import and otherwise run, modify and propagate the contents of its contributor 427 | version. 428 | 429 | In the following three paragraphs, a “patent license” is any express 430 | agreement or commitment, however denominated, not to enforce a patent (such as an 431 | express permission to practice a patent or covenant not to sue for patent 432 | infringement). To “grant” such a patent license to a party means to make 433 | such an agreement or commitment not to enforce a patent against the party. 434 | 435 | If you convey a covered work, knowingly relying on a patent license, and the 436 | Corresponding Source of the work is not available for anyone to copy, free of charge 437 | and under the terms of this License, through a publicly available network server or 438 | other readily accessible means, then you must either **(1)** cause the Corresponding 439 | Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the 440 | patent license for this particular work, or **(3)** arrange, in a manner consistent with 441 | the requirements of this License, to extend the patent license to downstream 442 | recipients. “Knowingly relying” means you have actual knowledge that, but 443 | for the patent license, your conveying the covered work in a country, or your 444 | recipient's use of the covered work in a country, would infringe one or more 445 | identifiable patents in that country that you have reason to believe are valid. 446 | 447 | If, pursuant to or in connection with a single transaction or arrangement, you 448 | convey, or propagate by procuring conveyance of, a covered work, and grant a patent 449 | license to some of the parties receiving the covered work authorizing them to use, 450 | propagate, modify or convey a specific copy of the covered work, then the patent 451 | license you grant is automatically extended to all recipients of the covered work and 452 | works based on it. 453 | 454 | A patent license is “discriminatory” if it does not include within the 455 | scope of its coverage, prohibits the exercise of, or is conditioned on the 456 | non-exercise of one or more of the rights that are specifically granted under this 457 | License. You may not convey a covered work if you are a party to an arrangement with 458 | a third party that is in the business of distributing software, under which you make 459 | payment to the third party based on the extent of your activity of conveying the 460 | work, and under which the third party grants, to any of the parties who would receive 461 | the covered work from you, a discriminatory patent license **(a)** in connection with 462 | copies of the covered work conveyed by you (or copies made from those copies), or **(b)** 463 | primarily for and in connection with specific products or compilations that contain 464 | the covered work, unless you entered into that arrangement, or that patent license 465 | was granted, prior to 28 March 2007. 466 | 467 | Nothing in this License shall be construed as excluding or limiting any implied 468 | license or other defenses to infringement that may otherwise be available to you 469 | under applicable patent law. 470 | 471 | ### 12. No Surrender of Others' Freedom 472 | 473 | If conditions are imposed on you (whether by court order, agreement or otherwise) 474 | that contradict the conditions of this License, they do not excuse you from the 475 | conditions of this License. If you cannot convey a covered work so as to satisfy 476 | simultaneously your obligations under this License and any other pertinent 477 | obligations, then as a consequence you may not convey it at all. For example, if you 478 | agree to terms that obligate you to collect a royalty for further conveying from 479 | those to whom you convey the Program, the only way you could satisfy both those terms 480 | and this License would be to refrain entirely from conveying the Program. 481 | 482 | ### 13. Use with the GNU Affero General Public License 483 | 484 | Notwithstanding any other provision of this License, you have permission to link or 485 | combine any covered work with a work licensed under version 3 of the GNU Affero 486 | General Public License into a single combined work, and to convey the resulting work. 487 | The terms of this License will continue to apply to the part which is the covered 488 | work, but the special requirements of the GNU Affero General Public License, section 489 | 13, concerning interaction through a network will apply to the combination as such. 490 | 491 | ### 14. Revised Versions of this License 492 | 493 | The Free Software Foundation may publish revised and/or new versions of the GNU 494 | General Public License from time to time. Such new versions will be similar in spirit 495 | to the present version, but may differ in detail to address new problems or concerns. 496 | 497 | Each version is given a distinguishing version number. If the Program specifies that 498 | a certain numbered version of the GNU General Public License “or any later 499 | version” applies to it, you have the option of following the terms and 500 | conditions either of that numbered version or of any later version published by the 501 | Free Software Foundation. If the Program does not specify a version number of the GNU 502 | General Public License, you may choose any version ever published by the Free 503 | Software Foundation. 504 | 505 | If the Program specifies that a proxy can decide which future versions of the GNU 506 | General Public License can be used, that proxy's public statement of acceptance of a 507 | version permanently authorizes you to choose that version for the Program. 508 | 509 | Later license versions may give you additional or different permissions. However, no 510 | additional obligations are imposed on any author or copyright holder as a result of 511 | your choosing to follow a later version. 512 | 513 | ### 15. Disclaimer of Warranty 514 | 515 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 516 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 517 | PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER 518 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 519 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE 520 | QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 521 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 522 | 523 | ### 16. Limitation of Liability 524 | 525 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY 526 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS 527 | PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, 528 | INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 529 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE 530 | OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE 531 | WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 532 | POSSIBILITY OF SUCH DAMAGES. 533 | 534 | ### 17. Interpretation of Sections 15 and 16 535 | 536 | If the disclaimer of warranty and limitation of liability provided above cannot be 537 | given local legal effect according to their terms, reviewing courts shall apply local 538 | law that most closely approximates an absolute waiver of all civil liability in 539 | connection with the Program, unless a warranty or assumption of liability accompanies 540 | a copy of the Program in return for a fee. 541 | 542 | _END OF TERMS AND CONDITIONS_ 543 | 544 | ## How to Apply These Terms to Your New Programs 545 | 546 | If you develop a new program, and you want it to be of the greatest possible use to 547 | the public, the best way to achieve this is to make it free software which everyone 548 | can redistribute and change under these terms. 549 | 550 | To do so, attach the following notices to the program. It is safest to attach them 551 | to the start of each source file to most effectively state the exclusion of warranty; 552 | and each file should have at least the “copyright” line and a pointer to 553 | where the full notice is found. 554 | 555 | 556 | Copyright (C) 2019 Chun-Hui Gao 557 | 558 | This program is free software: you can redistribute it and/or modify 559 | it under the terms of the GNU General Public License as published by 560 | the Free Software Foundation, either version 3 of the License, or 561 | (at your option) any later version. 562 | 563 | This program is distributed in the hope that it will be useful, 564 | but WITHOUT ANY WARRANTY; without even the implied warranty of 565 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 566 | GNU General Public License for more details. 567 | 568 | You should have received a copy of the GNU General Public License 569 | along with this program. If not, see . 570 | 571 | Also add information on how to contact you by electronic and paper mail. 572 | 573 | If the program does terminal interaction, make it output a short notice like this 574 | when it starts in an interactive mode: 575 | 576 | ggVennDiagram Copyright (C) 2019 Chun-Hui Gao 577 | This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. 578 | This is free software, and you are welcome to redistribute it 579 | under certain conditions; type 'show c' for details. 580 | 581 | The hypothetical commands `show w` and `show c` should show the appropriate parts of 582 | the General Public License. Of course, your program's commands might be different; 583 | for a GUI interface, you would use an “about box”. 584 | 585 | You should also get your employer (if you work as a programmer) or school, if any, to 586 | sign a “copyright disclaimer” for the program, if necessary. For more 587 | information on this, and how to apply and follow the GNU GPL, see 588 | <>. 589 | 590 | The GNU General Public License does not permit incorporating your program into 591 | proprietary programs. If your program is a subroutine library, you may consider it 592 | more useful to permit linking proprietary applications with the library. If this is 593 | what you want to do, use the GNU Lesser General Public License instead of this 594 | License. But first, please read 595 | <>. 596 | --------------------------------------------------------------------------------