Intro Thoughts

Status Quo

library(tidyverse)
contrast <- function(colour) {
  out   <- rep("gray20", length(colour))
  light <- farver::get_channel(colour, "l", space = "hcl")
  out[light < 50] <- "grey90"
  out
}


cors <- cor(mtcars)

# Melt matrix
df <- data.frame(
  col = colnames(cors)[as.vector(col(cors))],
  row = rownames(cors)[as.vector(row(cors))],
  value = as.vector(cors)
)

aes_color_after_fill <- function(fun = contrast){
  aes(colour = after_scale(fun(fill)))
}


# Basic plot
ggplot(df, aes(row, col, fill = value)) +
  geom_raster() +
  geom_text(aes(label = round(value, 2))) +
  coord_equal() + 
  aes_color_after_fill()

last_plot() + 
  scale_fill_viridis_c(direction =  1)

last_plot() + 
  scale_fill_viridis_c(direction = -1)
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.

Experiment

Closing remarks, Other Relevant Work, Caveats