How can one mix 2 or more color palettes to show a combined color value

前端 未结 1 696
陌清茗
陌清茗 2020-12-11 18:26

I\'m trying to create a plot where color represents the combination of several values. In the example below, I am applying increasing values for red associated with the x-co

相关标签:
1条回答
  • 2020-12-11 18:41

    Since I'm more familiar with ggplot, I'll show a solution using ggplot. This has the side benefit that, since the ggplot code is very simple, we can focus the discussion on the topic of colour management, rather than R code.

    1. Start by using expand.grid to create a data frame dat containing the grid of red and blue input values.
    2. Use the function rgb() to create the colour mix, and assign it to dat$mix
    3. Plot.

    The code:

    dat <- expand.grid(blue=seq(0, 100, by=10), red=seq(0, 100, by=10))
    dat <- within(dat, mix <- rgb(green=0, red=red, blue=blue, maxColorValue=100))
    
    library(ggplot2)
    ggplot(dat, aes(x=red, y=blue)) + 
      geom_tile(aes(fill=mix), color="white") + 
      scale_fill_identity()
    

    enter image description here


    You will notice that the colour scale is different from what you suggested, but possibly more intuitive.

    When mixing light, absence of any colour yields black, and presence of all colours yields white.

    This is clearly indicated by the plot, which I find rather intuitive to interpret.

    0 讨论(0)
提交回复
热议问题