Skip to contents

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.

Usage

venn_df_to_list(df)

Arguments

df

A data frame with columns id, name, value, type. Can be a plain data.frame, data.table, or tibble.

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:

id

Character. 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.

name

Character. Human-readable label shown in the diagram. For intersections this is optional - supply NA or "" to omit it.

value

Numeric. Area or size of this region.

type

Character. 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:

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")
# )