Curate Venn labels

curate_venn_labels(
  x,
  type = c("sign", "color"),
  curate_df = NULL,
  unicode = TRUE,
  blend_preset = "ryb",
  split = " ",
  ...
)

Arguments

x

vector of overlap labels.

type

character string where type="sign" will curate x into directional sign, and type="color" will curate x into corresponding directional color.

curate_df

data.frame or NULL with optional curation rules. The input is coerced to data.frame if necessary. The colnames are expected to include:

  • "from" - regular expression patterns

  • "sign" - replacement value when type="sign"

  • "color" - replacement R color when type="color"

unicode

logical indicating whether to use Unicode characters when type="sign". Note this argument only affects the default values, it is not applied when using a custom curate_df.

blend_preset

character string passed as preset to colorjam::blend_colors() to define the color wheel used during color blending operations.

split

character string used to split each "sign" in the input string x, assumed to be space character " ". This split is required to process replacement for each "sign" value without iteratively replacing values in x which can cause re-replacement of values which is not intended.

...

additional arguments are ignored.

Value

vector of labels or colors, based upon argument type.

Details

This venndir utility function is used to convert a basic directional label such as "0 1 0 -1" suitable for display. It can output either Unicode or non-Unicode text label, or a corresponding color.

The input currently recognizes directional labels such as "0 -1 1 0" or the character labels "agreement", "concordant", "mixed". Note that zeros "0" are typically removed before calling this function.

The input vector x is split using strsplit() using whitespace delimiter by default, then each full value is matched and replaced using "from" in curate_df.

When curate_df is not supplied, default values are generated for "from" values: "1", "-1", "0", "concordant|agreement", and "mixed". Values are matched using regular expression gsub() however the full string must match, therefore from="1" will only match "1" and will not match "-1".

The curate_df must contain these three colnames:

  • "from" - regular expression patterns, which will be surrounded by "^(" and ")$" to ensure complete match.

  • "sign" - character replacement for each value matched in "from" when type="sign".

  • "color" - character R color to assign to each value matched in "from", when type="color".

When two or more replacement values defined by curate_df[,"sign"] are present in one entry in x, the values are concatenated together with no whitespace. For example "1 1" becomes "^^" with no spacing. To impose whitespace between characters, define sign=c("^ ", "v ") to include whitespace. Any leading/trailing whitespace will be removed afterwards.

Examples

options("warn"=-1); # make them stop

venn_labels <- c("0 1 0 -1", "1 -1", "1 1 1", "mixed", "agreement", "1 1 0 0");
(curate_venn_labels(venn_labels, "sign"))
#> [1] "-↑-↓" "↑↓"   "↑↑↑"  "X"    "‖"    "↑↑--"
(curate_venn_labels(venn_labels, "sign", unicode=FALSE))
#> [1] "-^-v" "^v"   "^^^"  "X"    "="    "^^--"

(curate_venn_labels(venn_labels, "color"))
#> [1] "#9E4497FF" "#9E4497FF" "#B22222FF" "#737373FF" "#1874CDFF" "#B22222FF"

jamba::printDebug(as.list(curate_venn_labels(venn_labels, "sign")),
   collapse=", ",
   fgText=as.list(curate_venn_labels(venn_labels, "color")))
#> ##  (18:18:05) 03Sep2024:   -↑-↓, ↑↓, ↑↑↑, X, , ↑↑--