1. 程式人生 > 實用技巧 >UpSet——集合關係視覺化神器

UpSet——集合關係視覺化神器

分析背景

提到集合的視覺化,大家第一時間想到的是用Venn圖來展示,在前期的推文中,小編也給大家分享了venn圖的繪製方法。然而,值得一提的是,小編分享的方法是基於R語言,並將根據專案經驗,將常規的程式碼語句進行封裝,對於剛入門的小白來說,只需要整理好自己的資料,將資料傳入到函式中,即可得到高質量的Venn圖,方面快捷,省時省力。但是,當集合數多比如 7個以上的時候那就會看的眼花繚亂了。 針對上面這種情況,小編今天可大家編寫了一個用於多個集合資料視覺化小程式——集合圖,並且小編已經將其封裝成函式,小夥伴們只需將自己的資料傳入到函式中,即可做出高質量的圖片,儲存下來,AI編輯一下,就可以插入到自己的論文寫作中,話不多說,直接上指令碼!

分析方法

安裝R包

自定義函式

實戰演練

df = readFlie('./upset.txt',type = 'txt',row = F)
# 抽取資料,製造測試資料
set.seed(1234)
df_list = list('Symbol1'=sample(df$symbol,180),'Symbol2'=sample(df$symbol,200),
               'Symbol3'=sample(df$symbol,220),'Symbol4'=sample(df$symbol,240),
               'Symbol5'=sample(df$symbol,260
),'Symbol6'=sample(df$symbol,280), 'Symbol7'=sample(df$symbol,300),'Symbol8'=sample(df$symbol,310), 'Symbol9'=sample(df$symbol,150)) # 繪製集合圖 # 4維集合圖 wn_upset(df_list[1:4]) # 6維集合圖 wn_upset(df_list[1:6]) # 9維集合圖 wn_upset(df_list) # 儲存圖片 pdf('./up_set.pdf',height = 9,width = 16
) # 8維集合圖 wn_upset(df_list[1:8]) dev.off()

關注微信公眾號,回覆關鍵詞“upset”,獲取指令碼原始碼和測試資料。

參考文獻

  • Lex, A., Gehlenborg, N. Sets and intersections. Nat Methods 11, 779 (2014).

  • A. Lex, N. Gehlenborg, H. Strobelt, R. Vuillemot and H. Pfister, "UpSet: Visualization of Intersecting Sets," in IEEE Transactions on Visualization and Computer Graphics, vol. 20, no. 12, pp. 1983-1992, 31 Dec. 2014.

  • Conway J R, Lex A, Gehlenborg N. UpSetR: an R package for the visualization of intersecting sets and their properties[J]. Bioinformatics, 2017, 33(18): 2938-2940.