R-韦恩图系列-UpSetR

2021-11-01  本文已影响0人  小贝学生信

R-韦恩图系列-ggVennDiagram - 简书 (jianshu.com)
R-韦恩图系列-VennDiagram - 简书 (jianshu.com)
R-韦恩图系列-UpSetR - 简书 (jianshu.com)

当可视化多个(>5)集合的交集情况时,传统韦恩图的效果就比较复杂,不够直观。UpSetR包可进行相对更加高效的展示,而且用法也很简单。
参考:https://cran.r-project.org/web/packages/UpSetR/vignettes/

# install.packages("UpSetR")
library(UpSetR)
genes <- paste0("gene",1:1000)
set.seed(202111001)
gene_list <- list(set_A = sample(genes,100),
                  set_B = sample(genes,200),
                  set_C = sample(genes,300),
                  set_D = sample(genes,200),
                  set_E = sample(genes,300),
                  set_F = sample(genes,300))
upset(fromList(gene_list))

如上图分为三个部分

1.1、左下角:为原始各个集合大小的柱状图

默认选择Size Top 5的集合,其次集合排列顺序从上到下为size从小到大的顺序

upset(fromList(gene_list), 
      sets = names(gene_list), keep.order = TRUE)

2、右上角:各组排列组合的交集数目柱状图展示

upset(fromList(gene_list), sets = names(gene_list),
      nintersects =NA, empty.intersections = "on")

upset(movies, group.by = "sets", cutoff = 3)

order.by = "freq" 表示仅按照intersect size由高到低排序;order.by = "degree" 表示仅按照intersect 来源集合数由高到低排序;另外可进一步配合decreasing参数设置是否逆序。
参数表示

upset(fromList(gene_list), order.by = "freq", decreasing = F)

3 格式设置

upset(fromList(gene_list), 
      number.angles = 30,  
      point.size = 3.5, #左下角的点
      line.size = 2, #左下角的线
      mainbar.y.label = "Gene Sets Intersections", 
      sets.x.label = "Genes Per Set",
      mb.ratio = c(0.7, 0.3),
      text.scale = c(1.5, 1.1, 1.5, 1, 1.2, 1.5)) #见下图箭头
      #intersection size title, intersection size tick labels, 
      #set size title, set size tick labels, 
      #set names, numbers above bars)

以上是UpSetR的基础用法,此外还提供了三种高级作图技巧,下面仅展示效果,具体有需要时再学习。

[1] query 注释 感兴趣的intersect
[2] Attribute Plots
[3] Set Metadata
上一篇下一篇

猜你喜欢

热点阅读