Search code examples
rggplot2palette

Manually change some colors in a color palette


I am trying to come up with a palette with the most distinct colors. However, sometimes the colors generated are too light, or in shades of gray, and thus, not comfortable for viewers eyes. I want to manually replace these colors in my palette.

I used the code below to generate the palette. Can you help me with how to change the non-visible colors in the palette?

For exmaple, I would like to change the color #20 and #11 in the following palette.

n <- 36
palette <- distinctColorPalette(k = n, runTsne = F)
pie(rep(1, n), col=palette)

enter image description here


Solution

  • You can subset into the palette and change it into a colour of your liking. For example, to change the 20th colour:

    n <- 36
    palette <- distinctColorPalette(k = n, runTsne = F)
    palette[20] <- "#572D2D 
    

    You can do this for any colour you want to change with any colour to your liking.