当前位置: 首页 > news >正文

upset 绘制

好久没有更新,今天来一个upset图的绘制

1.1 安装包

#绘制upset的包现在看来有三个
## UpSet
### 最基本的upsetR包,使用方便,但是扩展不方便
devtools::install_github("hms-dbmi/UpSetR")
## complex-upset 
### UpSet的升级款 支持ggplot2
devtools::install_github('krassowski/complex-upset')
## ggupset
### 同样是UpSet的升级款 支持ggplot2
devtools::install_github("const-ae/ggupset")

示例数据

library(ggplot2)
library(ggupset)
library(ComplexUpset)
test.list <- list(set1 = c("a", "b", "c"),set2 = c("b", "c", "d", "e"),set3 = c("c", "d", "e", "f")
)

UpSetR

#对于list,利用fromlist()整理数据
UpSetR::upset(fromList(test.list), order.by = "degree", #还可以选择"degree")

UpSetR

ComplexUpset

# 要求输入的是矩阵,如果数据是list,用formlist()转化一下就可以
test.df <- fromList(test.list)
ComplexUpset::upset(test.df,intersect = colnames(test.df))
# 与UpSetR不同的是支持ggplot2语法, 例如
ComplexUpset::upset(test.df, intersect = colnames(test.df), wrap= TRUE) + ggtitle("This is a title")

ComplexUpset::upset(test.df,intersect = colnames(test.df))
ggtitle("This is a title")

ggupset

# 同样是支持ggplot2语法, 但是输入会更加复杂一些
# 主要是通过scale_x_upset()来控制upset的输出, 例如
test.df <- fromList(test.list) %>% apply(2, as.logical) %>% t() %>% as.tibble(rownames = "setsnames") %>% pivot_longer(cols = -setsnames, names_to = "Sets", values_to = "stat") %>% filter(stat) %>% select(-stat) %>% group_by(Sets) %>% summarize(Set = list(setsnames))
> test.df
# A tibble: 6 × 2Sets  Set      <chr> <list>   
1 V1    <chr [1]>
2 V2    <chr [2]>
3 V3    <chr [3]>
4 V4    <chr [2]>
5 V5    <chr [2]>
6 V6    <chr [1]>
> str(test.df)
tibble [6 × 2] (S3: tbl_df/tbl/data.frame)$ Sets: chr [1:6] "V1" "V2" "V3" "V4" ...$ Set :List of 6..$ : chr "set1"..$ : chr [1:2] "set1" "set2"..$ : chr [1:3] "set1" "set2" "set3"..$ : chr [1:2] "set2" "set3"..$ : chr [1:2] "set2" "set3"..$ : chr "set3"test.df %>% ggplot(aes(x = Set)) +geom_bar() +scale_x_upset(order_by = "degree",reverse = T, )

在这里插入图片描述

# 然后利用 ggplot2 增加亿点细节
test.df %>% ggplot(aes(x = Set)) +geom_bar() +scale_x_upset(order_by = "degree",reverse = T, )+geom_text(stat='count', aes(label=after_stat(count)), vjust=-1) + scale_y_continuous(name = "Intersection size",expand = c(0, 0), limits = c(0, 6))+theme(text = element_text(family = "ARIAL", colour = "black", size = 9))+xlab('')+theme_combmatrix(combmatrix.label.make_space = TRUE, combmatrix.label.width = NULL, combmatrix.label.height = NULL, combmatrix.label.extra_spacing = 3, combmatrix.label.total_extra_spacing = unit(10, "pt"), combmatrix.label.text = element_text(family = "ARIAL", colour = "Pink", size = 9), combmatrix.panel.margin = unit(c(1.5, 1.5), "pt"), combmatrix.panel.striped_background = TRUE, combmatrix.panel.striped_background.color.one = "white", combmatrix.panel.striped_background.color.two = "#F7F7F7", combmatrix.panel.point.size = 3, combmatrix.panel.line.size = 1.2, combmatrix.panel.point.color.fill = "red", combmatrix.panel.point.color.empty = "#E0E0E0", )+theme(panel.border = element_rect(colour = "black", fill = NA, size = 2))+theme(panel.background = element_blank(),axis.text.y = element_text(size = 9))

在这里插入图片描述

http://www.lryc.cn/news/268496.html

相关文章:

  • 声明 | 为打击假冒账号、恶意抄袭账号等诈骗活动,提升本账号权威,本博主特此郑重声明
  • 云计算:OpenStack 配置二层物理网卡为三层桥的接口
  • Python sanic框架钉钉和第三方打卡机实现
  • 微信小程序性能优化
  • java并发编程六 ReentrantLock,锁的活跃性
  • 深度学习 | DRNN、BRNN、LSTM、GRU
  • 代理模式:中间者的故事
  • 中间件系列 - Redis入门到实战(高级篇-多级缓存)
  • 是德科技E9304A功率传感器
  • 视频格式网络地址转换视频到本地,获取封面、时长,其他格式转换成mp4
  • 企业私有云容器化架构运维实战
  • Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用UserSet功能保存和载入相机的各类参数(C++)
  • STM32的以太网外设+PHY(LAN8720)使用详解(3):PHY寄存器详解
  • 缓存和缓冲的区别
  • C++高级-STL库概述
  • uniapp 统一获取授权提示和48小时间隔授权
  • Halcon点云重建
  • docker学习(二十一、network使用示例container、自定义)
  • 【Python机器学习系列】一文带你了解机器学习中的Pipeline管道机制(理论+源码)
  • 算法基础之整数划分
  • 关于“Python”的核心知识点整理大全47
  • Android 8.1 设置USB传输文件模式(MTP)
  • 模型量化 | Pytorch的模型量化基础
  • adb和logcat常用命令
  • 千巡翼X4轻型无人机 赋能智慧矿山
  • 【Android 13】使用Android Studio调试系统应用之Settings移植(一):编译服务器的配置、AOSP源码的下载、编译、运行
  • 【1】Docker详解与部署微服务实战
  • C# JsonString转Object以及Object转JsonString
  • 华为OD机试真题-中文分词模拟器-2023年OD统一考试(C卷)
  • 【并发设计模式】聊聊 基于Copy-on-Write模式下的CopyOnWriteArrayList