Skip to contents

Set intersections as a bar chart over a membership matrix. Venn diagrams stop being readable at four sets and stop being drawable at five; UpSet replaces the areas with an explicit matrix, so it scales to dozens of sets and stays exact.

Usage

upset(
  data,
  sets,
  membership,
  set_sizes = NULL,
  total = NULL,
  bar_fraction = 0.55,
  show_set_sizes = TRUE,
  dot_radius = 5,
  bar_color = NULL,
  empty_dot_color = NULL,
  y_label = "intersection size",
  theme = NULL,
  width = NULL,
  height = NULL,
  element_id = NULL
)

Arguments

data

A data frame with a numeric size column, one row per intersection, in the order to draw them.

sets

Character vector of set names, top to bottom.

membership

Logical or 0/1 matrix, intersections x sets, saying which sets each intersection belongs to.

set_sizes

Numeric vector of per-set totals for the left-hand bars.

total

Universe size, shown in the corner.

bar_fraction

Fraction of the height given to the intersection bars.

show_set_sizes

Draw the per-set total bars.

dot_radius

Matrix dot radius in pixels.

bar_color, empty_dot_color

Fills for the bars and filled dots, and for dots not in the intersection. NULL uses the theme.

y_label

Axis label for the intersection bars.

theme

Optional named list of theme overrides.

width, height

Widget dimensions (any valid CSS size).

element_id

Optional explicit DOM id.

Value

An htmlwidget object.

Details

Intersections are exclusive: a column counts the elements in precisely that combination of sets and no others. That is what makes the columns sum to the union rather than double-counting, and it is why a small A + B bar next to large A and B bars is evidence of mutual exclusivity rather than an artefact. upset_intersections() computes them from a logical matrix.

Examples

m <- matrix(c(TRUE, FALSE, FALSE, TRUE, TRUE, TRUE), nrow = 3, byrow = TRUE)
upset(data.frame(size = c(40, 25, 12)), sets = c("A", "B"), membership = m)