最近剛好用到韋恩圖,但是由于term比較多,VennDiagram的可視化效果并不好。然后再一個(gè)帖子里看到了UpSetR和Y叔的改進(jìn)版本upsetplot。
UpSetR
一、一般情況下,我喜歡用最直接的方式輸入
這種方式可以很方便的選擇自己想展示的任意幾個(gè)cluster之間的交集。
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))

可以根據(jù)參數(shù)改變每一個(gè)bar的顏色
二、使用table方式輸入
當(dāng)數(shù)據(jù)量較大,或者需要更復(fù)雜的展示的時(shí)候,可以使用table方式輸入。
我們來(lái)看一下系統(tǒng)提供是movies數(shù)據(jù)
movies <- read.csv(system.file("extdata","movies.csv",package = "UpSetR"), header = TRUE, sep=";")
View(movies)

類似的數(shù)據(jù)類型
類似的格式的數(shù)據(jù)可以使用tidyr包中的pivot_wider函數(shù)生成,這個(gè)包中有很多函數(shù)對(duì)于數(shù)據(jù)變形很好用。
upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5),
order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE))

movies
其他更加復(fù)雜的參數(shù)可以自行探索。