The upset() function is the primary interface for generating UpSet plots. It allows you to extend UpSetR functionality with ggplot2's extensibility.
Key features include:
annotations: A list of ggplot2 objects that add data visualizations (like boxplots or violin plots) corresponding to the intersections.queries: A list of upset_query() objects used to highlight specific intersections or sets with custom colors and fills.min_size: Filters intersections by a minimum size.width_ratio: Adjusts the width ratio of the plot components.
Note: If you use ggbeeswarm::geom_quasirandom in your annotations, ensure the ggbeeswarm package is installed; otherwise, you can use geom_jitter from 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))
+ 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
)