• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

Visualizing Intersection Sets with UpSet Plot: A Replacement for Venn Diagrams

datavizpyr · February 17, 2020 ·

Venn Diagrams are the bread and butter of visualizing intersections of multiple sets. One of the reasons for Venn Diagram is popular because it is simple and intuitive. However, when you have more than three sets, Venn Diagram gets really complicated to make sense.

UpSet plots are a great replacement for Venn Diagram for visualize intersections of two or more sets. In this post, we will use the R package UpSetR and make simple upset plots using a toy example.

library(UpSetR)

Let us create some simple data to make intersections using UpSetR. Here we sample 6 numbers with replacements from between 1 and 10. We create four such sets: a,b,c, and d.

set.seed(42)
a = sample(1:6,10,replace=T)
b = sample(1:6,10,replace=T)
c = sample(1:6,10,replace=T)
d = sample(1:6,10,replace=T)

We can see that we have four sets with different number of common elements between them. In this post, we will see how to visualize the overlap of multiple sets like these using UpSet plots.

print(unique(a))
## [1] 1 5 2 4
print(unique(b))
## [1] 1 5 6 4 2 3
print(unique(c))
## [1] 4 5 2 3 1
print(unique(d))
## [1] 2 6 3 4 5

UpSet Plot Example With Two Sets

Let us consider a simple example with two sets. With Venn diagram, when we compare two sets, we will have intersection between two sets, and two numbers unique to each set.

UpSet visualizes intersections among the sets

in a matrix layout and introduces aggregates based on groupings and queries. The matrix layout enables the effective representation of associated data, such as the number of elements in the aggregates and intersections, as well as additional summary statistics derived from subset or element attributes.

list_input <- list(a=a,b=b)
upset(fromList(list_input))
Simple UpSet Plot
Simple UpSet Plot
list_input <- list(a=a,b=b)
# UpSet Plot Ordered by frequency
upset(fromList(list_input), 
      order.by = "freq")
Intersection of Two sets with UpSet plot
Intersection of Two sets with UpSet plot
list_input <- list(a=a,b=b)
upset(fromList(list_input), 
      order.by = "freq",
      text.scale=2,
      point.size = 3, 
      line.size = 1.5)
Customizing UpSet for for Two Sets
Customizing UpSet for for Two Sets

UpSet Plot Example With Three Sets

list_input <- list(a=a,b=b,c=c)
upset(fromList(list_input), 
      order.by = "freq",
      text.scale=2,
      point.size = 3,
      line.size = 1.5)
Visualizing Intersection of Three sets with UpSet plot
Visualizing Intersection of Three sets with UpSet plot

UpSet Plot Example With Four Sets

list_input <- list(a=a,b=b,c=c,d=d)
# Visualizing_Intersection_of_Four_sets_with_upset_plot
upset(fromList(list_input), 
      order.by = "freq",
      text.scale=2,
      point.size = 3,
      line.size = 1.5)
Visualizing Intersection of Four sets with UpSet plot
Visualizing Intersection of Four sets with UpSet plot

Related posts:

How to Make Heatmap with ggplot2?How To Make Simple Heatmaps with ggplot2 in R? Coloring Barplots by a Variable with ggplot2Coloring Barplots with ggplot2 in R RColorBrewer color blind friendly palettesIntroduction to Color Palettes in R with RColorBrewer How to Make Barplots with Error bars in R?How To Make Barplots with Error bars in ggplot2?

Filed Under: R, UpSet Plot R, Venn Diagrams Tagged With: R, UpSetR

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version