Below is a set of blue shades we want to reproduce (and interpolate if more intermediate colours are needed).
require(grid)
grid.raster(t(blues9), interpolate = FALSE)
We define a function of n (number of colours) that maps a vector (1/n, …, 1) to a linear interpolation of R, G, B values in a colour ramp,
blues <- function(n) {
slopes <- c(-0.94, -0.67, -0.39)
matrix((1:n)/n, ncol = 1) %*% slopes + 0.95
}
Let's try it with 10 colours,
test <- blues(10)
test
## R G B
## [1,] 0.856 0.883 0.911
## [2,] 0.762 0.816 0.872
## [3,] 0.668 0.749 0.833
## [4,] 0.574 0.682 0.794
## [5,] 0.480 0.615 0.755
## [6,] 0.386 0.548 0.716
## [7,] 0.292 0.481 0.677
## [8,] 0.198 0.414 0.638
## [9,] 0.104 0.347 0.599
## [10,] 0.010 0.280 0.560
grid.raster(t(rgb(test)), interpolate = FALSE)