Learn R Programming

VennDiagram (version 1.2.0)

draw.pairwise.venn: Draw a Venn Diagram with Two Sets

Description

Creates a Venn diagram with two sets. Creates Euler diagrams when the dataset meets certain conditions.

Usage

draw.pairwise.venn(area1, area2, cross.area, category = rep("", 2), euler.d = TRUE, scaled = TRUE, inverted = FALSE, ext.text = TRUE, 
lwd = rep(2, 2), lty = rep("solid", 2), col = rep("black", 2), fill = NULL, alpha = rep(0.5, 2), label.col = rep("black", 3), cex = rep(1, 3), 
fontface = rep("plain", 3), fontfamily = rep("serif", 3), cat.pos = c(-50, 50), cat.dist = rep(0.025, 2), cat.cex = rep(1, 2), 
cat.col = rep("black", 2), cat.fontface = rep("plain", 2), cat.fontfamily = rep("serif", 2), cat.just = rep(list(c(0.5, 0.5)), 2), 
cat.default.pos = "outer", cat.prompts = FALSE, ext.pos = rep(0, 2), ext.dist = rep(0, 2), ext.line.lty = "solid", ext.length = rep(0.95, 2), 
ext.line.lwd = 1, rotation.degree = 0, rotation.centre = c(0.5, 0.5), ind = TRUE, sep.dist = 0.05, offset = 0, ...)

Arguments

area1
The size of the first set
area2
The size of the second set
cross.area
The size of the intersection between the sets
category
A vector (length 2) of strings giving the category names of the sets
euler.d
Boolean indicating whether to draw Euler diagrams when conditions are met or not
scaled
Boolean indicating whether to scale circle sizes in the diagram according to set sizes or not
inverted
Boolean indicating whether the diagram should be mirrored long the vertical axis or not
ext.text
Boolean indicating whether to place area labels outside the circles in case of small partial areas or not
lwd
A vector (length 2) of numbers giving the lwd of the circles' circumferences
lty
A vector (length 2) giving the lty of the circles' circumferences
col
A vector (length 2) giving the colours of the circles' circumferences
fill
A vector (length 2) giving the colours of the circles' areas
alpha
A vector (length 2) giving the alpha transparency of the circles' areas
label.col
A vector (length 3) giving the colours of the areas' labels
cex
A vector (length 3) giving the cex of the areas' labels
fontface
A vector (length 3) giving the fontface of the areas' labels
fontfamily
A vector (length 3) givibg the fontfamily of the areas' labels
cat.pos
A vector (length 2) giving the positions (in degrees) of the category names along the circles, with 0 (default) at the 12 o'clock location
cat.dist
A vector (length 2) giving the distances (in npc units) of the category names from the edges of the circles (can be negative)
cat.cex
A vector (length 2) giving the cex of the category names
cat.col
A vector (length 2) giving the colours of the category names
cat.fontface
A vector (length 2) giving the fontface of the category names
cat.fontfamily
A vector (length 2) giving the fontfamily of the category names
cat.just
List of 2 vectors of length 2 indicating horizontal and vertical justification of each category name
cat.default.pos
Either 'outer' or 'text' to specify the default location of category names (cat.pos and cat.dist are handled differently)
cat.prompts
Boolean indicating whether to display help text on category name positioning or not)
ext.pos
A vector (length 1 or 2) giving the positions (in degrees) of the external area labels along the circles, with 0 (default) at the 12 o'clock location
ext.dist
A vector (length 1 or 2) giving how far to place the external area labels relative to its anchor point
ext.line.lty
A vector (length 1 or 2) giving the lty of the lines connecting the external area labels to their anchor points
ext.length
A vector (length 1 or 2) giving the proportion of the lines connecting the external area labels to their anchor points actually drawn
ext.line.lwd
A vector (length 1 or 2) giving the lwd of the lines connecting the external area labels to their anchor points
rotation.degree
Number of degrees to rotate the entire diagram
rotation.centre
A vector (length 2) indicating (x,y) of the rotation centre
ind
Boolean indicating whether the function is to automatically draw the diagram before returning the gList object or not
sep.dist
Number giving the distance between circles in case of an Euler diagram showing mutually exclusive sets
offset
Number between 0 and 1 giving the amount of offset from the centre in case of an Euler diagram showing inclusive sets
...
Additional arguments to be passed to or from other methods, including margin, which indicates amount of whitespace around the final diagram in npc units

Value

  • Returns an object of class gList containing the grid objects that make up the diagram. Also displays the diagram in a graphical device unless specified with ind = FALSE. Grid::grid.draw can be used to draw the gList object in a graphical device.

Details

Euler diagrams are drawn for mutually exclusive sets (cross.area == 0), inclusive sets (area1 == 0 or area2 == 0), and coincidental sets (area1 == 0 and area2 == 0) if euler.d == TRUE. The function defaults to placing the larger set on the left. The function also defaults to giving the first element of each argument to the larger set. inverted or rotation.degree can be used to reverse this.

Examples

Run this code
# A simple two-set diagram
venn.plot <- draw.pairwise.venn(100, 70, 30, c("First", "Second"));

# Same diagram as above, but without scaling
venn.plot <- draw.pairwise.venn(100, 70, 30, c("First", "Second"), scaled = FALSE);

# A more complicated diagram Demonstrating external area labels
venn.plot <- draw.pairwise.venn(
	area1 = 100, 
	area2 = 70, 
	cross.area = 68, 
	category = c("First", "Second"),
	fill = c("blue", "red"),
	lty = "blank",
	cex = 2,
	cat.cex = 2,
	cat.pos = c(285, 105),
	cat.dist = 0.09,
	cat.just = list(c(-1, -1), c(1, 1)),
	ext.pos = 30,
	ext.dist = -0.05,
	ext.length = 0.85,
	ext.line.lwd = 2,
	ext.line.lty = "dashed"
	);

# Demonstrating an Euler diagram
venn.plot <- draw.pairwise.venn(
	area1 = 100, 
	area2 = 70,
	cross.area = 0,
	category = c("First", "Second"),
	cat.pos = c(0, 180),
	euler.d = TRUE,
	sep.dist = 0.03,
	rotation.degree = 45
	);

# Writing to file
tiff(filename = "Single-set Venn diagram.tiff", compression = "lzw");
	
venn.plot <- draw.pairwise.venn(100, 70, 30, c("First", "Second"));

grid.draw(venn.plot);

dev.off();

Run the code above in your browser using DataLab