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

Description Usage Arguments Details Value Author(s) Examples

View source: R/draw.pairwise.venn.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
draw.pairwise.venn(area1, area2, cross.area, category = rep("", 2),
    euler.d = TRUE, scaled = TRUE, inverted = FALSE,
    ext.text = TRUE, ext.percent = rep(0.05, 3), 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, cex.prop =
    NULL, print.mode = "raw", sigdigs = 3, ...)

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 (Venn Diagrams with moveable circles)

scaled

Boolean indicating whether to scale circle sizes in the diagram according to set sizes or not (euler.d must be true to enable this)

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

ext.percent

A vector (length 3) indicating the proportion that a partial area has to be smaller than to trigger external text placement. The elements allow for individual control of the areas in the order of area1, area2 and intersect area.

lwd

A vector (length 2) of numbers giving the line width of the circles' circumferences

lty

A vector (length 2) giving the line dash pattern 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 size of the areas' labels

fontface

A vector (length 3) giving the fontface of the areas' labels

fontfamily

A vector (length 3) giving 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 size 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

One of c('outer', '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 12 o'clock

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 dash pattern 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 width 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

cex.prop

A function or string used to rescale areas

print.mode

Can be either 'raw' or 'percent'. This is the format that the numbers will be printed in. Can pass in a vector with the second element being printed under the first

sigdigs

If one of the elements in print.mode is 'percent', then this is how many significant digits will be kept

...

Additional arguments to be passed, including margin, which indicates amount of whitespace around the final diagram in npc units

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. inverted or rotation.degree can be used to reverse this.

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.

Author(s)

Hanbo Chen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# A simple two-set diagram
venn.plot <- draw.pairwise.venn(100, 70, 30, c("First", "Second"));
grid.draw(venn.plot);
grid.newpage();

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

# 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"
	);
grid.draw(venn.plot);
grid.newpage();

# 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 = tempfile(
        pattern = 'Pairwise_Venn_diagram',
        fileext = '.tiff'
        ),
    compression = "lzw");
    
grid.draw(venn.plot);
dev.off();

VennDiagram documentation built on Oct. 30, 2021, 5:06 p.m.