`R` 中带有 `venneuler` 的维恩图:从图中删除集合名称并添加元素名称
Venn Diagrams with `venneuler` in `R`: delete the name of the set from the plot and add elements name
在过去的几天里,我一直在尝试弄清楚如何从任意数量的集合中绘制维恩图,并遇到了 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)
生成如下图:
这个数字正是我要找的。无论如何,我想从图中删除集合的名称(class 1、class 2 等),而是添加每个集合中包含的元素(例如 gene1、gene2)。
你可以直接修改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
。此代码:
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)
生成如下图:
这个数字正是我要找的。无论如何,我想从图中删除集合的名称(class 1、class 2 等),而是添加每个集合中包含的元素(例如 gene1、gene2)。
你可以直接修改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)