| venn_df_to_list | R Documentation |
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.
venn_df_to_list(df)
df |
A data frame with columns |
A list of set entries suitable for hd_geom_venn(),
hd_spec_venn(), and hd_venn_df().
The input data frame must have these four columns:
idCharacter. For type = "set": a single identifier such as
"A". For type = "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 NA or "" 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).
Each row is converted by the corresponding constructor:
type = "set" calls hd_venn_set()
type = "intersect" calls hd_venn_intersect()
where ids is the comma-split vector from id.
The result is identical to building the list by hand with those functions.
hd_venn_df(), hd_spec_venn(), hd_geom_venn()
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")
# )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.