Converts a tidy data frame with columns id, name, value, and type
into the nested list format required by hd_geom_venn() and
hd_spec_venn(). This is the recommended way to build venn data from
a spreadsheet, CSV, or database query without calling hd_venn_set() and
hd_venn_intersect() row by row.
Value
A list of set entries suitable for hd_geom_venn(),
hd_spec_venn(), and hd_venn_df().
Data frame format
The input data frame must have these four columns:
idCharacter. For
type = "set": a single identifier such as"A". Fortype = "intersect": a comma-separated list of the set ids that overlap, such as"A,B"or"A,B,C". Spaces around commas are trimmed automatically.nameCharacter. Human-readable label shown in the diagram. For intersections this is optional - supply
NAor""to omit it.valueNumeric. Area or size of this region.
typeCharacter. Either
"set"(a single circle) or"intersect"(an overlap region between two or more circles).
Relationship to hd_venn_set / hd_venn_intersect
Each row is converted by the corresponding constructor:
type = "set"callshd_venn_set()type = "intersect"callshd_venn_intersect()whereidsis the comma-split vector fromid.
The result is identical to building the list by hand with those functions.
Examples
venn_df <- data.frame(
type = c("set", "set", "intersect"),
id = c("A", "B", "A,B"),
name = c("Oslo", "Bergen", "Both"),
value = c(120, 95, 40)
)
sets <- venn_df_to_list(venn_df)
# Equivalent to:
# list(
# hd_venn_set("A", "Oslo", 120),
# hd_venn_set("B", "Bergen", 95),
# hd_venn_intersect(c("A", "B"), 40, name = "Both")
# )
