Change the layout of the Venn diagram
2
1
Entering edit mode
4 months ago
G.S ▴ 60

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 • 744 views
ADD COMMENT
2
Entering edit mode
4 months ago
zx8754 12k

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

ADD COMMENT
2
Entering edit mode
4 months ago

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

ADD COMMENT

Login before adding your answer.

Traffic: 2189 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6