This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Change the layout of the Venn diagram

Hello

I plotted this venn diagram using ggplot2. but I would like to change its orientation to be horizontal.

At the moment, The label is not clear. I have tried to use hjust but it did not help to adjust the label. Any suggestion would be helpful. Thanksenter image description here

 venn_by_gene = function(d, gene, title="Venn diagram"){
  require(ggVennDiagram)

  d = d %>% filter(id==gene) 
  km_list = list(HRSV_RBV = d$kmer_rbv, 
                 HRSV = d$kmer_rsv)
  v = ggVennDiagram(km_list) + 
    scale_fill_gradient2(low="gray",mid="yellow",high = "cyan") +
    ggtitle(title)+
    theme(plot.title = element_text(hjust = 0.5, face ="bold"), 
          legend.position = "none")

  return(v)
}
r ggplot2 venn

2 answers

It is a ggplot object, so just flip it:

library(ggVennDiagram)
library(ggplot2)

#example from manuals:
#https://cran.r-project.org/web/packages/ggVennDiagram/readme/README.html

genes <- paste("gene",1:1000,sep="")
set.seed(20231214)
x <- list(A=sample(genes,300),
          B=sample(genes,525),
          C=sample(genes,440),
          D=sample(genes,350))

ggVennDiagram(x[1:2],label = "none") +
  coord_flip()

enter image description here

I generally don't like the implementation in ggVennDiagram

Here's an alternative you might like using the eulerr package.

library(eulerr)

venn.list <- list(Set1 = LETTERS[1:13],
                  Set2 = LETTERS[10:27])
set.seed(12345)
plot(euler(venn.list), 
     fills = list(fill = c("Set1" = "#54928D",
                           "Set2" =  "#941C50"), 
                  alpha = 0.9),
     labels = list(col = "black", font = 2),
     quantities = list(col = "black", font = 2))

The advantage of euler diagrams is you get a visual representation of the overlap as well as the overall structure

enter image description here

Log in to answer this question.