Reputation: 1
I'm plotting some data from a list of named vectors using fromList() with the UpSetR package. But I need to sort the combination matrix by sets, just like an example on the ggupset GitHub page where from left to right you have first the sets with "Action", then "Action" + "Animation" etc
In other words: I'm trying to get my plot to look like this: Desired outcome (https://github.com/const-ae/ggupset)
But my plots look like this: Not desired outcome
I'm trying to use the ggupset package, but I cannot figure out how to use a list of named vectors for the data. So, that would also help: How to use a list of named vectors as data input for ggupset?
Upvotes: 0
Views: 293
Reputation: 1
I solved my problem coding a function that transforms a list of named vectors into a dataframe with each element paired to it's set. Basically the input that ggupset neads.
I'll post it here in case someone finds it useful:
library(VennDiagram)
library(stringr)
fromListtoggUpSet <- function(namedvectors){
clusters <- get.venn.partitions(namedvectors)
output <- data.frame()
genes <- c()
for (set in 1:nrow(clusters[clusters$..count..>0,])){
genes <- c(genes, clusters[clusters$..count..>0,]$..values..[[set]])
}
output <- rbind(output, list("Genes" = genes))
output <- cbind(output, "Set" = NA)
fila <- 0
for (set in 1:nrow(clusters[clusters$..count..>0,])){
name <- str_split_1(gsub(".*\\((.*)\\).*", "\\1",
str_split_1(clusters[clusters$..count..>0,]$..set..[[set]], "∖")[1]), "∩")
for (n in 1:clusters[clusters$..count..>0,]$..count..[[set]]){
output[n+fila, 2] <- list(list(name))
}
fila <- fila + clusters[clusters$..count..>0,]$..count..[[set]]
}
return(output)
}
Upvotes: 0