| hd_geom_venn | R Documentation |
Creates a Venn or Euler diagram layer that is added to an hd() object
via +. The diagram is described by a list of set entries supplied via
the sets argument.
hd_geom_venn(
sets,
series_name = "Venn Diagram",
label_font_size = "14px",
value_suffix = "",
use_names = FALSE,
show_legend = FALSE,
legend_offset_y = 0.6,
legend_height = 0.85,
...
)
sets |
A list of set entries. See Data format above.
Use |
series_name |
Character. Series label shown in the Highcharts
chart. Default |
label_font_size |
Character. CSS font-size for set labels.
Default |
value_suffix |
Character. Appended to each region's value label.
Default |
use_names |
Logical. If |
show_legend |
Logical. If |
legend_offset_y |
Numeric (0–1). Vertical shift of the venn grob. Increase to move diagram upward and create more space for legend. |
legend_height |
Numeric (0–1). Relative height of the venn grob. Decrease to allocate more space for legend. |
... |
Additional arguments forwarded to |
An S3 object of class "hd_geom" for use with +.hd.
Supply only the intersections that actually exist in your data. Highcharts will separate circles that share no intersection entry, producing an Euler diagram automatically. No separate geom is needed. Note: mathematically impossible layouts (e.g. three pairs all intersect but the triple intersection is zero) cannot be rendered and will error. If chart fails to display as intended, it might be due to the intersection is larger than the single sets that contain them.
sets is a list of named lists. Each element describes either a single
set or an intersection between sets:
list(
# Single sets - must have name and value
list(sets = list("A"), name = "Animals", value = 5),
list(sets = list("B"), name = "Four legs", value = 4),
list(sets = list("C"), name = "Mineral", value = 2),
# Intersections - sets contains two or more names, value is overlap size
list(sets = list("A", "B"), value = 3)
)
Use hd_venn_set() and hd_venn_intersect() to build entries without
typing the nested list structure by hand.
Because sets is a plain R list, it can be built and extended
programmatically with c() or append():
base <- list(
hd_venn_set("A", "Animals", 5),
hd_venn_set("B", "Four legs", 4)
)
extended <- c(base, list(hd_venn_intersect(c("A","B"), 3)))
hd(mode = "dynamic") +
hd_geom_venn(sets = extended)
Uses Highcharts' native "venn" series type.
All features (labels, tooltips, interactivity) work out of the box.
series_name and label_font_size are highcharter-only options.
Requires the eulerr package (preferred) or
ggVennDiagram in Suggests. Install with
install.packages("eulerr").
hd_venn_df(), hd_venn_set(), hd_venn_intersect(), venn_df_to_list()
# Build the set list with helper constructors
my_sets <- list(
hd_venn_set("A", "Animals", value = 5),
hd_venn_set("B", "Four legs", value = 4),
hd_venn_set("C", "Mineral", value = 2),
hd_venn_intersect(c("A", "B"), value = 3)
)
# Dynamic (interactive)
hd(mode = "dynamic") +
hd_geom_venn(sets = my_sets) +
hd_opts(title = "Animals and Minerals")
# Static - requires eulerr or ggVennDiagram
hd(mode = "static") +
hd_geom_venn(sets = my_sets) +
hd_opts(title = "Animals and Minerals")
# Extend a base list programmatically
base_sets <- list(
hd_venn_set("A", "Oslo", value = 120),
hd_venn_set("B", "Bergen", value = 95)
)
extended <- c(base_sets, list(
hd_venn_intersect(c("A", "B"), "Both", value = 40)
))
hd(mode = "dynamic") +
hd_geom_venn(sets = extended) +
hd_opts(title = "City overlap")
# Convert a data.frame to a venn set list with hd_venn_df() function
id = c("A", "B", "A,B")
name = c("Oslo", "Bergen", "Both")
value = c(80, 30, 10)
n = c(120, 95, 40)
type = c(rep("set", 2), "intersect")
df <- data.frame(type, id, name, value, n)
df2 <- hd_venn_df(df, output = "spec")
hd_make(df2, "venn", hd_opts(title = "City overlap"), mode = "dynamic")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.