Rstudio Venn Diagram with several numbers

514 Views Asked by At

I Have two dataset, where im counting the number of each sample within that dataset. And i want to combine the numbers of each sample for both dataset and then create a VennDiagram using R, with the main numbers of the largest dataset and in parenthesis the smaller dataset numbers.

The R code i'm currently using now

grid.newpage()
temp <- draw.triple.venn(area1 = 428, 
             area2 = 145, 
             area3 = 303, 
             n12 = 26, 
             n23 = 16, 
             n13 = 14, 
             n123 = 9,
             category = c("text1", "text2", "text3"),
             scaled=FALSE,
             ext.text=FALSE)

grid.draw(temp)
pdf(file="figure1.pdf")
grid.draw(temp)
dev.off()

The result i get

enter image description here

What i would like to create

enter image description here

I have looked at the eulerr package and the Venn diagram package but i cant seem to figure out if there is a way to make this possible.

All help is much appreciated. Many thanks.

1

There are 1 best solutions below

0
On

Not sure what the 'small' dataset looks like, but this does the trick

Here, you add traces to the grid with custom labels, and y-coordinates proportional to the y-coordinates of you 'large' dataset

library(VennDiagram)

temp <- draw.triple.venn(area1 = 428, 
                     area2 = 145, 
                     area3 = 303, 
                     n12 = 26, 
                     n23 = 16, 
                     n13 = 14, 
                     n123 = 9,
                     category = c("text1", "text2", "text3"),
                     scaled=FALSE,
                     ext.text=FALSE)


temp[[17]] <- temp[[13]]
temp[[17]]$y <- temp[[13]]$y * 0.8
temp[[17]]$label <- '(3)'

temp[[18]] <- temp[[9]]
temp[[18]]$y <- temp[[9]]$y * 0.95
temp[[18]]$label <- '(4)'

temp[[19]] <- temp[[7]]
temp[[19]]$y <- temp[[7]]$y * 0.95
temp[[19]]$label <- '(5)'

grid.draw(temp)