I just used the Venn diagram recently, but because there are more terms, the visualization effect of VennDiagram is not good. Then another post saw the improved version of UpSetR and Uncle Y upsetplot.
In this way, you can easily choose the intersection between any clusters you want to display.
colorPalette<-c("#e41a1c","#377eb8","#4daf4a","9ecae1","#6baed6","#4292c6")
library(UpSetR)
input <- c(
'Type 1'= 578,
'Type 2' = 284,
'Type 3' = 488,
'Type 1&Type 3' =205,
'Type 2&Type 3' =89,
'Type 1&Type 2&Type 3' =20)
data <- fromExpression(input)
upset(data, nsets = 9, sets = c('Type 1', 'Type 2' , 'Type 3'),
keep.order = TRUE,matrix.color ="#b35806", main.bar.color = colorPalette,
sets.bar.color = c("#e41a1c","#377eb8","#4daf4a"),
point.size = 4, line.size = 1.3, mainbar.y.label = "IntersectionSize",
sets.x.label = "", mb.ratio = c(0.60, 0.40), text.scale = c(2, 2, 0.5, 0.5,2, 3))
When the amount of data is large, or when a more complex display is required, you can use table input.
Let's take a look at the movies data provided by the system
movies <- read.csv(system.file("extdata","movies.csv",package = "UpSetR"), header = TRUE, sep=";")
View(movies)
Data in a similar format can be generated using the pivot_wider function in the tidyr package. There are many functions in this package that are very useful for data transformation.
upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5),
order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE))
Other more complex parameters can be explored on their own.