[R] colored venn diagram

David Winsemius dwinsemius at comcast.net
Thu May 20 05:37:29 CEST 2010

On May 19, 2010, at 7:15 PM, Shi, Tao wrote:

> Hi list,
> This is probably too much to ask, but I'm wondering if there is a  
> ready-to-use function somewhere that allows me to color one area of  
> a venn diagram (e.g. the intersection of two sets)?

There is an intersectDiagrapm in plotrix that accepts color arguments,  
although it is not really a Venn diagram.

The venn function in gplots does not accept color. It is a wrapper to  
getVennCounts and drawVennDiagram, and if you hack the second function  
you can get colors. For the example in the help page for Venn, you  
need to find the section that handles the correct number of sets and  
add a color argument to the polygon call. If you want intersections  
you will need transparency. I do not know how to address specific  

require(seqinr)  # for col2alpha for transparency

getAnywhere(drawVennDiagram)   # add an assignment operator and trim  
out this stuff----
A single object matching ‘drawVennDiagram’ was found
It was found in the following places
with value
----------end trimming--------------
function (data, small = 0.7, showSetLogicLabel = FALSE, simplify =  
     numCircles <- NA
# make mod to n==4 section
  +             polygon(relocate_elp(elps, 45, 130, 170),  
col=col2alpha("red", 0.5) )
+             polygon(relocate_elp(elps, 45, 200, 200),  
col=col2alpha("blue", 0.5) )
+             polygon(relocate_elp(elps, 135, 200, 200))
+             polygon(relocate_elp(elps, 135, 270, 170))
... And then pass the result from venn to drawVennDiagram:

gv <- venn(input)
  drawVennDiagram(data = gv, small = 0.7, showSetLogicLabel = FALSE,
             simplify = FALSE)

Set #1 in pink set2 in blue and the intersection is purple.


> Thanks!
> ...Tao
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

More information about the R-help mailing list