Learn R Programming

ComplexUpset

Quick links: Documentation | Installation | R examples | Python examples

Showcase

Get all the goodies of UpSetR, but with full extensibility of ggplot2.

library(ggplot2)
library(ComplexUpset)

if(!require(ggplot2movies)) install.packages('ggplot2movies')
movies = ggplot2movies::movies
genres = c('Action', 'Animation', 'Comedy', 'Drama', 'Documentary', 'Romance')

upset(
    movies,
    genres,
    annotations = list(
        'Length'=ggplot(mapping=aes(x=intersection, y=length)) + geom_boxplot(),
        'Rating'=ggplot(mapping=aes(x=intersection, y=rating))
            # if you do not want to install ggbeeswarm, you can use geom_jitter
            + ggbeeswarm::geom_quasirandom(aes(color=log10(votes)))
            + geom_violin(width=1.1, alpha=0.5)
    ),
    queries=list(
        upset_query(
            intersect=c('Drama', 'Comedy'),
            color='red',
            fill='red',
            only_components=c('intersections_matrix', 'Intersection size')
        ),
        upset_query(
            set='Drama',
            fill='blue'
        ),
        upset_query(
            intersect=c('Romance', 'Drama'),
            fill='yellow',
            only_components=c('Length')
        )
    ),
    min_size=10,
    width_ratio=0.1
)

The full list of examples is available in the documentation; it also contains instructions for the use from Python.

Install

To get the most recent version, open R and run:

if(!require(devtools)) install.packages("devtools")
devtools::install_github("krassowski/complex-upset")

Alternatively, to get a stable CRAN release (which may be one version behind at times):

install.packages('ComplexUpset')

Or, if you use conda/mamba:

conda install -c conda-forge r-complexupset

How it compares to other packages?

  • UpSetR is a powerful tool and the pioneer in the UpSet visualisations; it was not designed to be extended with ggplot components. Unfortunately, the repository is no longer active (for two years now).
  • ggupset uses scales to convert a single plot to upsets plots, e.g. with scale_x_upset - a really nice approach, recommended for simple ggplot.
  • a cowplot-based upset was demonstrated in an online publication, however cowplot (a great tool at the time) got superseded by even greater tool: patchwork, which is what is used by ComplexUpset.
  • ComplexHeatmap also offers a way to generate UpSet plots with annotations; while not ggplot2-centered, it provides extensive customization options, with a clear API. It may be the best choice if you already use it for heatmaps.

Use whichever tool you find the most useful for your particular use. The rational of making this repository public is not only to share the code, but also to demonstrate how simple it is now to create complex visualisations with patchwork (without the need to learn the ggplot internals).

For the interactive use, check out the VCG/upset. Regardless of the tool chosen, you may want to cite (Lex et al, 2014) when using UpSet plots, especially in fields still dominated by Venn diagrams.

Get inspired

Here are example publications and preprints including figures generated with this library:

The list is not meant to be exhaustive, but representative of applications to different fields, and of different usage ideas. You are welcome to add your own publication by suggesting an edit.

Testing

The unit tests are run with testhat, and the visual "doppelganger" tests use vdiffr.

The test cases for visual tests are auto-generated from the examples in the documentation; after changing or adding an example, please run:

  • scripts/prepare_for_tests.sh to generate updated test cases, and
  • scripts/manage_visual_tests.sh to validate the generated images.

Acknowledgments

Originally developed in course of a DPhil programme in Women's & Reproductive Health at OxfordNuffieldWRH.

Copy Link

Version

Install

install.packages('ComplexUpset')

Monthly Downloads

3,472

Version

1.3.3

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Micha<c5><82> Krassowski

Last Published

December 11th, 2021

Functions in ComplexUpset (1.3.3)

upset_default_themes

Default themes modified by specified arguments
upset_text_percentage

Generate percentage label of the intersection/union sizes ratio
scale_color_venn_mix

Color scale for Venn diagram
reverse_log_trans

Logarithmic scale for use with upset_set_size()
upset_test

Test for differences between intersections
geom_venn_label_region

Label for a region of Venn diagram
intersection_ratio

Barplot annotation of relative intersections sizes
intersection_size

Barplot annotation of intersections sizes
scale_fill_venn_mix

Fill scale for Venn diagram
upset

Compose an UpSet plot
upset_annotate

Annotation panel shorthand
upset_set_size

Prepare layers for sets sizes plot
upset_stripes

Define appearence of the stripes
upset_data

Prepare data for UpSet plots
upset_themes

List of default themes for upset components
upset_modify_themes

Default themes modified by specified component-specific arguments
upset_mode

Layer defining the intersection mode for the data to be displayed
upset_query

Highlight chosen sets or intersections
geom_venn_label_set

Label for a set of Venn diagram
aes_percentage

Generate mapping for labeling percentages
create_upset_abc_example

Create an example dataset with three sets: A, B and C
geom_venn_circle

Circle for Venn diagram
get_size_mode

Retrieve symbol for given mode that can be used in aesthetics mapping with double bang (!!)
arrange_venn

Arrange points for Venn diagram
geom_venn_region

Region of Venn diagram
compare_between_intersections

Compare covariates between intersections
intersection_matrix

Prepare layers for sets sizes plot