A single-call convenience wrapper that accepts the same tidy data frame as
venn_df_to_list() and returns either an hd_spec_venn object (for the
declarative API) or an hd_geom layer (for the composable + API),
depending on the output argument.
Usage
hd_venn_df(
df,
output = c("spec", "geom"),
series_name = "Venn Diagram",
label_font_size = "14px",
value_suffix = "",
use_names = FALSE,
show_legend = FALSE
)Arguments
- df
A data frame with columns
id,name,value,type. Seevenn_df_to_list()for the full format description.- output
Character.
"spec"(default) returns anhd_spec_venn;"geom"returns anhd_geomlayer for use with+.- series_name
Character. Passed to
hd_geom_venn()whenoutput = "geom". Default"Venn Diagram".- label_font_size
Character. Passed to
hd_geom_venn()whenoutput = "geom". Default"14px".- value_suffix
Character. Passed to
hd_geom_venn(). Suffix appended to value labels (e.g."%"). Default"".- use_names
Logical. Passed to
hd_geom_venn(). Use human-readable names instead of ids in labels. DefaultFALSE.- show_legend
Logical. Passed to
hd_geom_venn(). Show a legend beneath the diagram. DefaultFALSE.
Details
This means you never need to call venn_df_to_list(), hd_spec_venn(),
or hd_geom_venn() directly when starting from a data frame.
Which output to use
output = "spec"(default)Returns an
hd_spec_vennobject. Pass tohd_make()just like any other spec. Best for reporting pipelines and scripts that separate data from presentation.output = "geom"Returns an
hd_geomlayer. Add to anhd()object with+. Best for interactive exploration and inline charts.
Declarative API (output = "spec")
df <- data.frame(
type = c("set", "set", "intersect"),
id = c("A", "B", "A,B"),
name = c("Oslo", "Bergen", "Both"),
value = c(120, 95, 40)
)
spec_v <- hd_venn_df(df)
hd_make(spec_v, "venn", hd_opts(title = "City overlap"))Composable API (output = "geom")
hd(mode = "dynamic") +
hd_venn_df(df, output = "geom") +
hd_opts(title = "City overlap")Examples
# \donttest{
df <- data.frame(
type = c("set", "set", "intersect"),
id = c("A", "B", "A,B"),
name = c("Oslo", "Bergen", "Both"),
value = c(120, 95, 40)
)
# Declarative API
spec_v <- hd_venn_df(df)
hd_make(spec_v, "venn", hd_opts(title = "City overlap"))
# Composable API
hd(mode = "dynamic") +
hd_venn_df(df, output = "geom") +
hd_opts(title = "City overlap")
# static mode
hd(mode = "static") +
hd_venn_df(df, output = "geom") +
hd_opts(title = "City overlap")
# }
