Venn diagram

Euler diagrams are Venn diagrams without the requirement that all set interactions be present (whether they are empty or not). That is, depending on input, eulerr will sometimes produce Venn diagrams but sometimes not.

Prominent R packages that produce euler and/or venn diagrams are: eVenn, VennDiagram, venn, colorfulVennPlot, and venneuler.

Generate data

set.seed(1)
# Generate 3 sets of 200 words
set1 <- paste(rep("word_" , 300) , sample(c(1:1000) , 300 , replace=F) , sep="")
set2 <- paste(rep("word_" , 250) , sample(c(1:1000) , 250 , replace=F) , sep="")
set3 <- paste(rep("word_" , 200) , sample(c(1:1000) , 200 , replace=F) , sep="")
set4 <- paste(rep("word_" , 350) , sample(c(1:1000) , 350 , replace=F) , sep="")

Generate venn diagram with VennDiagram package

Three data sets (draw.triple.venn)

suppressPackageStartupMessages(library(VennDiagram))
 
# # Prepare a palette of 4 colors with R colorbrewer:
library(RColorBrewer)
myCol <- brewer.pal(3, "Pastel2")

# Plotting
venn.diagram(
        x = list(set1, set2, set3),
        category.names = c("A", "B", "C"),
        filename = 'Venn_diagram_three.png',
        output=TRUE,

        # Output features
        imagetype = "png",
        height = 480,
        width = 480,
        resolution = 300,
        compression = "lzw",

        # Circles
        lwd = 2,
        lty = 'blank',
        fill = myCol,

        # Numbers
        cex = .6,
        fontface = "bold",
        fontfamily = "sans",

        # Set names
        cat.cex = 0.6,
        cat.fontface = "bold",
        cat.default.pos = "outer",
        cat.pos = c(-60, 60, 180),
        cat.dist = c(0.055, 0.055, 0.055),
        cat.fontfamily = "sans",
        rotation = 1
)

Four data sets (draw.quad.venn)

venn.diagram(
        x = list(set1, set2, set3, set4),
        category.names = c("A", "B", "C", "D"),
        filename = 'Venn_diagram_four.png',
        output=TRUE,

        # Circles
        lwd = 2,
        #lty = 'blank',
        fill = rainbow(4),

        # Numbers
        cex = .6,
        fontface = "bold",
        fontfamily = "Arial",

        # Set names
        cat.cex = 0.6,
        cat.fontface = "bold",
        cat.default.pos = "outer",
        cat.fontfamily = "Arial"
)

Generate venn diagram with eulerr package

suppressPackageStartupMessages(library(eulerr))

fit <- euler(c(A = length(set1), B = length(set2), C = length(set3), 
               "A&B" = length(intersect(set1, set2)), "A&C" = length(intersect(set1, set3)), "B&C" = length(intersect(set2, set3)),
                "A&B&C" = length(intersect(intersect(set1, set2), set3))))
plot(fit, 
     fills = list(fill = rainbow(3)),
     quantities = list(fontsize = 12), 
     edges = list(lty = 1:3),
     main = "Euler Diagram")

CHENYUAN

CHENYUAN
Pursuing the dream and the best future

CHENYUAN Blog Homepage

因为不想遗忘! 在这个信息大爆炸的年代,最重要的是对知识的消化-吸收-重铸。每天学了很多东西,但是理解的多少,以及能够运用多少是日后成功的关键。作为一个PhD,大脑中充斥了太多的东西,同时随着年龄的增长,难免会忘掉很多事情。所以只是为了在众多教程中写一个自己用到的,与自己...… Continue reading