This function converts a named vector with colors as the values to a format that can be passed to the colourScale =.

get_d3_colourScale(namedvector)

Arguments

namedvector

a named character vector where the names are the levels and the values are the respective colors

Value

a string

Examples

get_d3_colourScale(c("A" = "blue", "B" = "red"))
#> [1] "d3.scaleOrdinal() .domain([\"A\", \"B\"]) .range([\"blue\", \"red\"])"

# also see here: https://github.com/fbreitwieser/sankeyD3/issues/20#issuecomment-999624150