gpt4 book ai didi

r - `venneuler` 中的维恩图 `R` : delete the name of the set from the plot and add elements name

转载 作者:行者123 更新时间:2023-12-04 15:06:28 25 4
gpt4 key购买 nike

在过去的几天里,我一直在试图弄清楚如何从任意数量的集合中绘制维恩图并遇到了 R包裹venneuler .这段代码:

genes <- paste("gene",1:20,sep="")

df = data.frame(term=character(), class=character(), stringsAsFactors = FALSE)
for (k in 1:15) {
df2=data.frame(term=sample(genes,10), class = rep(paste("class ",k,sep=""),10), stringsAsFactors =
FALSE)
df<-rbind(df,df2)
}


library(rJava)
library(UpSetR)
library(tidyverse)
library(venneuler)
library(grid)

v <- venneuler(df)

par(cex = 0.5)
plot(v)
产生这样的图:
enter image description here
这个数字正是我要找的。无论如何,我想从图中删除集合的名称(第 1 类、第 2 类等),而是添加每个集合中包含的元素(例如基因 1、基因 2)。

最佳答案

可以直接修改v$labels :

library(venneuler)
library(dplyr)
library(stringr)

v <- venneuler(df)

par(cex = 0.5)

# Create the list of genes per class
classgenes <- df %>% group_by(class) %>%
summarize(labels = paste(stringr::str_sort(term,numeric=T),collapse = '\n')) %>%
ungroup


# Order the class new label according to v$labels order
newlabels <- left_join(data.frame(class = v$labels), classgenes)
#> Joining, by = "class"

# Modify the labels
v$labels <- newlabels$labels

plot(v)

关于r - `venneuler` 中的维恩图 `R` : delete the name of the set from the plot and add elements name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65994218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com