unionplot: Draw a union plot

Description Usage Arguments Value References

View source: R/unionplot.R

Description

A union plot is like a Venn diagram, in that it shows the union between three groups. Unlike a Venn diagram, the number of shared units (in this case, OTUs) is not indicated by a number but by a point drawn for each OTU, which can then be coloured by a factor of interest e.g. Phylum. Also unlike a Venn diagram, the regions are not indicated by shared circles but by hexagons and trapezoids; the points are arranged on a hexagonal grid. This allows the regions to be resized according to the number of shared OTUs.

There's probably already a name for this kind of plot, but I couldn't find it after some cursory googling so just named it "union plot". Email me if you know the actual name and I'll fix it.

Usage

1
2
unionplot(OTUTable, group = "Sample", colour = "Phylum", point_size = 1,
  collapse = 1)

Arguments

OTUTable

an OTU table in tidy format, i.e. a data frame with at least an "OTU" column as well as columns for the group and colour factors.

group

a string corresponding to the name of a factor column in OTUTable, which determines the three groups that will form the three cardinal regions in the plot. Defaults to "Sample".

colour

a string corresponding to the name of a factor column in OTUTable, which determines the colours of the points. colour is mandatory; if you don't want the points to be coloured, you should be drawing a Venn diagram instead. Defaults to "Phylum".

point_size

(optional) number to be passed to geom_point() as the point size. Defaults to 1.

collapse

(optional) integer. If > 1, each point in the plot will not represent a single OTU but this number of OTUs, with the true number rounded up to the nearest multiple of this value (there are no fractional points).

Value

Returns a ggplot2 grob containing the union plot, which can then be viewed (e.g. with print()) or saved (e.g. with ggsave()) at leisure. Note that the placement of text labels in the plot isn't the greatest; you'll probably need to go in and move them using an image editing suite.

References

Amit Patel's page on hexagonal grids was invaluable in creating this function, and many of the routines in here are derived from algorithms found there http://www.redblobgames.com/grids/hexagons


wilkox/unionplot documentation built on May 4, 2019, 5:26 a.m.