Description Usage Arguments Value Examples
Plot a 2-4 way Venn diagram. Use prepare_venn
to
prepare the input data.frame data
in the correct format.
See Examples section below for basic usage instructions.
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 | geom_venn(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
type = "discrete",
set_name_pos = NULL,
set_name_colour = NULL,
set_name_size = 5,
set_name_face = NULL,
set_name_family = NULL,
set_total = FALSE,
set_total_pos = c(0, -0.15),
set_total_colour = NULL,
set_total_size = 4,
set_total_face = NULL,
set_total_family = NULL,
count_colour = "black",
count_size = 5,
count_face = NULL,
count_family = NULL,
count_nudge = 0.06,
percentage = TRUE,
percentage_digits = 1,
percentage_colour = "black",
percentage_size = 3,
percentage_face = NULL,
percentage_family = NULL,
percentage_nudge = -count_nudge,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
|
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
type |
|
set_name_pos |
Optional. |
set_name_colour |
|
set_name_size |
|
set_name_face |
|
set_name_family |
|
set_total |
|
set_total_pos |
Optional. |
set_total_colour |
|
set_total_size |
|
set_total_face |
|
set_total_family |
|
count_colour |
|
count_size |
|
count_face |
|
count_family |
|
count_nudge |
|
percentage |
|
percentage_digits |
|
percentage_colour |
|
percentage_size |
|
percentage_face |
|
percentage_family |
|
percentage_nudge |
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Returns a layer ggproto object with geom = GeomVenn
.
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 55 56 57 | library(ggplot2)
# Start with a list of vectors to compare.
# Within each vector, there must not be any duplicated elements.
lst <- list(
Set1 = c(letters[1:8]),
Set2 = c(letters[20:26]),
Set3 = c(letters[8:20])
)
# Use prepare_venn() to convert the list into a data.frame.
# of the correct format. You can add extra columns to the data.frame.
# Here we add a column named fill.
df <- prepare_venn(lst, fill = c("blue", "green", "red"))
# Now we plot a basic Venn diagram
ggplot() +
geom_venn(aes(set_name = set_name, elements = elements), data = df)
# As this is just a normal ggplot layer we can add whatever we want
# to the plot. Some annotations for example.
ggplot() +
geom_venn(aes(set_name = set_name, elements = elements), data = df) +
annotate("curve", x = -1.2, xend = -0.75, y = -0.6, yend = -0.3,
curvature = 0.3, arrow = arrow(length = unit(2, "mm"))) +
annotate("text", x = -1.25, y = -0.6, label = "Interesting!", hjust = "right")
# Use theme_void() to get a plain background
ggplot() +
geom_venn(aes(set_name = set_name, elements = elements), data = df) +
theme_void()
# Add set totals
ggplot() +
geom_venn(aes(set_name = set_name, elements = elements),
data = df, set_total = TRUE) +
theme_void()
# Remove percentages
ggplot() +
geom_venn(aes(set_name = set_name, elements = elements),
data = df, percentage = FALSE, count_nudge = 0) +
theme_void()
# Add discrete fills to the ellipses
ggplot() +
geom_venn(aes(set_name = set_name, elements = elements, fill = fill),
data = df, type = "discrete") +
theme_void() +
scale_fill_identity()
# Add continuous fills to the ellipse segments
ggplot() +
geom_venn(aes(set_name = set_name, elements = elements, fill = count),
data = df, type = "continuous") +
theme_void() +
scale_fill_gradientn(colors = alpha(c("white", "red"), 0.7))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.