ggplot2绘制venn图展示hub基因

2023-10-24 14:02:54 浏览数 (2)

欢迎关注R语言数据分析指南

加载R包

代码语言:javascript复制
library(ggvenn)
library(tidyverse)
library(ggtext)
library(magrittr)
library(ggpubr)
library(cowplot)

导入数据

代码语言:javascript复制
A <- read_tsv("diff.txt",col_names = F)
B <- read_tsv("OS.txt",col_names = F)
C <- read_tsv("WGCNA.txt",col_names = F)

绘制韦恩图

代码语言:javascript复制
p1 <- list(A=A$X1,B=B$X1,C=C$X1) %>% 
  ggvenn(show_percentage = T,show_elements = F,label_sep = ",",
         digits = 1,stroke_color = "white",
         fill_color = c("#1E90FF", "#FF8C00","#4DAF4A"),
         set_name_color = c("#1E90FF","#FF8C00","#4DAF4A"))

构建函数提取交并集

代码语言:javascript复制
# 使用Reduce函数来计算列表中所有向量的交集
Intersect <- function(x) {
  Reduce(intersect, x)
}

# 使用Reduce函数来计算列表中所有向量的并集
Union <- function(x) {
  Reduce(union, x)
}

# 计算两个列表的差集
diff <- function(x, y) {
  xx <- Intersect(x)
  yy <- Union(y)
  setdiff(xx, yy)
}

提取交集

代码语言:javascript复制
xx <- list(A=A$X1,B=B$X1,C=C$X1)

拼图

代码语言:javascript复制
p2 <- Intersect(xx) %>% as.data.frame() %>% set_colnames("hub-gene") %>% 
  ggtexttable(rows = NULL, theme = ttheme("lBlueWhite"))

p1 %>% ggdraw()   draw_plot(p2,scale=0.008,x=0.62,y=0.27,width=0.5,height=0.1)

0 人点赞