Tuesday, 14 April 2015

Plotting Venn Diagrams in R....

One of the challenges with R is that there is always more than one way to do things. Often there are many ways to do things. Today, I have set myself the task of trying to work out how to draw Venn Diagrams in R.

A Google search using "r", "venn" and "diagram" revealed the following options:

With five ways to do something, which is the best? Well the short answer to that is the one that you like and thus the personal preference element which is key to R becomes the most important issue. 

I have spent a little while trying to work out the differences between the various packages. 

There is one key point: do you know the numbers for your Venn Diagram or do you want to find these out.

The package VennDiagram generally requires you to have all the numbers already. It produces nice diagrams and the examples include ways to generate high quality TIFF plots. 
Here is an example of the four way Venn Diagram made with the example code:


I think it's pretty and I can appreciate how to change and add the information. This is the code (from  :

# Reference four-set diagram
install.packages("VennDiagram")

library(VennDiagram)

venn.plot <- draw.quad.venn( area1 = 72, 
                             area2 = 86,
                             area3 = 50, 
                             area4 = 52, 
                             n12 = 44, 
                             n13 = 27, 
                             n14 = 32, 
                             n23 = 38, 
                             n24 = 32,
                             n34 = 20,
                             n123 = 18,
                             n124 = 17,
                             n134 = 11, 
                             n234 = 13,
                             n1234 = 6,
                             category = c("First", "Second", "Third", "Fourth"),
                             fill = c("orange", "red", "green", "blue"),
                             lty = "dashed",
                             cex = 2, cat.cex = 2, cat.col = c("orange", "red", "green", "blue") );
                             


 

2 comments:

  1. There is also an R package called "venn", it can draw diagrams up to 7 sets:
    https://cran.r-project.org/web/packages/venn/index.html

    ReplyDelete
  2. Find more venn diagram examples in the diagram community of Creately online diagramming and collaboration software. There are 100s of venn diagram examples and templates in the community to be used freely.

    ReplyDelete