欢迎关注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)