OHDSI Home | Forums | Wiki | Github

OHDSI palette for plots

For those who care about such things: @msuchard and I created a 5-color palette for plots that should go well with the OHDSI logo colors. The palette has been checked for color blinded, but it is hard to do that conclusively so let me know if you have issues distinguishing the colors.

You can find the palette here.

To use in R:

colors <- c("#336B91", "#69AED5", "#11A08A", "#FBC511", "#EB6622")


Going to need more than 5 for Cohort Pathway visualizations…

@Chris_Knoll: There are only so many colors a human can distinguish in a single visualization, so perhaps Cohort Pathway needs a different way to identify cohorts in the plot?

This tool allows you to inspect if your visualization works for different types of color-blindness. Might be good to try the Cohort Pathway output on that.

Pretty sure that number is greater than 5, lol. Maybe I could limit the max number of event cohorts to the number of colors available…I’ll think about it.

Maybe a palette option?

I was thinking more of using numbers in the plot (or some other marking like cohort name abbreviations) in addition to colors to identify cohorts. I would prefer not to limit the number of event cohorts.

This is what GPT suggested

Define the initial OHDSI colors

ohdsiColors ← c("#336B91", “#69AED5”, “#11A08A”, “#FBC511”, “#EB6622”)

Create a function to interpolate between these colors

colorInterpolate ← grDevices::colorRampPalette(ohdsiColors)

Generate a palette of 20 colors (you can adjust the number of colors as needed)

extendedPalette ← colorInterpolate(20)

Optionally, adjust the brightness and saturation to make it more ‘viridis-like’

Using the colorspace package to adjust these properties

if (!requireNamespace(“colorspace”, quietly = TRUE)) install.packages(“colorspace”)
extendedPaletteAdjusted ← colorspace::darken(extendedPalette, amount = 0.1)

Print the palette


Plot the palette

plot(1:20, pch = 19, cex = 3, col = extendedPaletteAdjusted, xlab = “Index”, ylab = “Color”, main = “Extended OHDSI Color Palette”)

And here is a function

Define the function to create an OHDSI color palette

createOhdsiPalette <-
  function(seedColors = c("#336B91", "#69AED5", "#11A08A", "#FBC511", "#EB6622"),
           numColors = 100,
           adjustAmount = 0.1,
           darken = TRUE) {
    # Function to interpolate colors
    colorInterpolate <- grDevices::colorRampPalette(seedColors)
    # Generate the palette
    extendedPalette <- colorInterpolate(numColors)
    # Adjust the brightness or saturation based on user input
    if (darken) {
      adjustedPalette <-
        colorspace::darken(extendedPalette, amount = adjustAmount)
    } else {
      adjustedPalette <-
        colorspace::lighten(extendedPalette, amount = adjustAmount)