djsir-data / djprtheme

ggplot2 theme package for the Victorian Department of Jobs, Precincts and Regions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create Colorblind friendly corporate palette

mrjoh3 opened this issue · comments

using the current corporate colours define colour palettes that maximise colour contrast. We will need palettes of different lengths

I have already assessed the current colours and selected 7 where at least one pairwise contrast comparison is above 4.5. When creating palettes with less colours we can use a similar approach

# pairwise comparison of current palette
mt <- as.matrix(
    c(
        "#14826D",
        "#62BB46",
        "#C0E4B5",
        "#BCD3EF",
        "#1D9EC3",
        "#2A6FA2",
        "#004676",
        "#1F1547",
        "#53565A",
        "#745ECF"
    )
)
cd <- sapply(mt, colorspace::contrast_ratio, mt)
rownames(cd) <- mt

# select contrast above 4.5
cond <- cd > 4.5 & upper.tri(cd, FALSE)
pos <- which(cond, arr.ind = TRUE)

# convert to dataframe and extract unique colours
df <- data.frame(values = cd[pos], ind = rownames(cd)[pos[,1]], pp = rownames(cd)[pos[,2]])
contrast_pal <- unique(c(df$ind, df$pp))

I have then checked this colour selection for colour blindness impact using the website below:

https://projects.susielu.com/viz-palette?colors=[%22#C0E4B5%22,%22#BCD3EF%22,%22#62BB46%22,%22#1D9EC3%22,%22#004676%22,%22#1F1547%22,%22#53565A%22]&backgroundColor=%22white%22&fontColor=%22black%22&mode=%22normal%22

PR approved, this issue can be closed.