加载R包library(ggvenn) library(tidyverse) library(ggtext) library(magrittr) library(ggpubr) library(cowplot)
导入数据A <- read_tsv("diff.txt",col_names = F) B <- read_tsv("OS.txt",col_names = F) C <- read_tsv("WGCNA.txt",col_names = F)
绘制韦恩图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"))
构建函数提取交并集# 使用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) }
提取交集xx <- list(A=A$X1,B=B$X1,C=C$X1)
拼图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)
|