Install the ComplexUpset package and download the toy dataset (movies):

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

Load the libraries:

library(ComplexUpset)
library(ggplot2)

Loading data

We will be using the movies from ggplot2movies package:

movies = ggplot2movies::movies
head(movies)
## # A tibble: 6 x 24
##   title  year length budget rating votes    r1    r2    r3    r4    r5    r6
##   <chr> <int>  <int>  <int>  <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 $      1971    121     NA    6.4   348   4.5   4.5   4.5   4.5  14.5  24.5
## 2 $100…  1939     71     NA    6      20   0    14.5   4.5  24.5  14.5  14.5
## 3 $21 …  1941      7     NA    8.2     5   0     0     0     0     0    24.5
## 4 $40,…  1996     70     NA    8.2     6  14.5   0     0     0     0     0  
## 5 $50,…  1975     71     NA    3.4    17  24.5   4.5   0    14.5  14.5   4.5
## 6 $pent  2000     91     NA    4.3    45   4.5   4.5   4.5  14.5  14.5  14.5
## # … with 12 more variables: r7 <dbl>, r8 <dbl>, r9 <dbl>, r10 <dbl>,
## #   mpaa <chr>, Action <int>, Animation <int>, Comedy <int>, Drama <int>,
## #   Documentary <int>, Romance <int>, Short <int>

And intersect following columns:

genres = c('Action', 'Animation', 'Comedy', 'Drama', 'Documentary', 'Romance', 'Short')

Simple UpSet plot

Example plot:

upset(
    movies, genres,
    base_annotations=list('Intersection size'=intersection_size(counts=FALSE)),
    min_size=100,
    width_ratio=0.1
)
## [1] "Converting non-logical columns to binary: Action, Animation, Comedy, Drama, Documentary, Romance, Short"
## Warning: Removed 7 rows containing missing values (geom_segment).

To remove the warning about conversion use:

movies[, genres] = sapply(movies[, genres], as.logical)

A bit more complex UpSet plot

upset(
    movies, genres,
    base_annotations=list(
      'Intersection size'=intersection_size(counts=FALSE)
    ),
    min_size=100,
    width_ratio=0.1,
    height_ratio=0.7,
    sort_sets='ascending',
    themes=upset_modify_themes(
        list(
            'intersections_matrix'=theme(text=element_text(size=8)),
            'overall_sizes'=theme(axis.text.x=element_text(angle=90))
        )
    ),
    annotations=list(
      'Rating'=list(
            aes=aes(x=intersection, y=rating),
            geom=list(
                geom_violin(width=1.1, alpha=0.5),
                stat_summary(
                    fun.y=mean,
                    fun.ymin=function(x) { quantile(x, 0.25) },
                    fun.ymax=function(x) { quantile(x, 0.75) },
                    colour='grey'
                )
            )
        )
    ),
    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', 'Comedy'),
            fill='yellow',
            only_components=c('Rating')
        )
    )
)