Upsetplot

upsetPlot(DataOrSets, setName, varargin)[source]

Generates an UpSet plot, a visualisation of set intersections

An UpSet plot is an alternative to Venn diagrams, especially suited for larger numbers of sets. The plot shows:

  • Horizontal bars representing the size of each set

  • Vertical bars representing the size of intersections between sets

  • A matrix of dots and connecting lines below the bars, indicating which sets are involved in each intersection

USAGE:

[hFig, axI, axS, axL] = upsetPlot (DataOrSets, setName, varargin)

INPUTS:
  • DataOrSets – Either a logical N x M matrix (Data, rows = elements, columns = sets), or a 1 x M cell array of vectors (Sets, raw sets of elements). When a cell array is given, the function internally builds the membership matrix.

  • setName1 x M cell array of set names.

OPTIONAL INPUTS:

varargin – Optional name-value argument pairs:

  • bar1Color - colour(s) for intersection bars (default teal gradient)

  • bar2Color - colour(s) for set size bars (default blue gradient)

  • lineColor - colour for connection lines (default grey)

  • includeSingletons - logical, whether to include single-set intersections in the top bars (default false, which excludes them)

  • Parent - parent figure to draw into; if provided, the plot is created in (and the figure cleared for) this figure

OUTPUTS:
  • hFig – Handle to the created figure.

  • axI – Intersection axes (top bars).

  • axS – Set size axes (left bars).

  • axL – Links matrix axes (dots and lines).

Example

% Example 1 (binary matrix, whole-figure saving): rng(5) setName = {‘RB1’,’PIK3R1’,’EGFR’,’TP53’,’PTEN’}; Data = rand([200,5]) > .85; [h, axI] = upsetPlot(Data, setName); % excludes singletons by default savefig(h, ‘upset_matrix.fig’) % save MATLAB figure print(h, ‘-dpdf’, ‘upset_matrix.pdf’) % export to PDF exportgraphics(axI, ‘upset_intersections.png’) % export just top bars

% Example 2 (raw sets, provide parent to avoid Live Editor clean-up): A = [1 2 5]; B = [2 3]; C = [1 4 5]; f = figure(‘Color’,’w’); % parent from base workspace [h, axI, axS, axL] = upsetPlot({A,B,C}, {‘A’,’B’,’C’}, ‘includeSingletons’, true, ‘Parent’, f); exportgraphics(axS, ‘upset_set_sizes.png’); % left bars only saveas(h, ‘upset_whole.png’); % whole figure