Question: I'm trying to draw a set of rectangles, each with a fill color representing some value between 0 and 1. Ideally, I would like to use any standard colormap.

Note that the rectangles are not placed in a nice grid, so using `imagesc`, `surf`, or similar seems unpractical. Also, the `scatter` function does not seem to allow me to assign a custom marker shape. Hence, I'm stuck to plotting a bunch of Rectangles in a for-loop and assigning a `FillColor` by hand. 

What's the most efficient way to compute RGB triplets from the scalar values? I've been unable to find a function along the lines of `[r,g,b] = val2rgb(value,colormap).` Right now, I've built a function which computes 'jet' values, after inspecting `rgbplot`(jet). This seems a bit silly. I could, of course, obtain values from an arbitrary colormap by interpolation, but this would be slow for large datasets.

So, what would an efficient `[r,g,b] = val2rgb(value,colormap)` look like?

Answer: 
You can use `complete` from package `tidyr` :

```
library("tidyr")
data %>% complete(area, year, fill = list(population.served = 0))
# # A tibble: 16 × 3
#         area   year population.served
#       <fctr> <fctr>             <dbl>
# 1  Cambridge Year.1               200
# 2  Cambridge Year.2               202
# 3  Cambridge Year.3               204
# 4  Cambridge Year.4               207
# 5  Edinburgh Year.1                 0
# 6  Edinburgh Year.2                 0
# 7  Edinburgh Year.3                 0
# 8  Edinburgh Year.4               210
# .....

```
An approach with the fast `data.table` package:

```
library(data.table)
setDT(data)[CJ(area = area, year = year, unique = TRUE), on = c('area', 'year')
            ][is.na(population.served), population.served := 0][]

```

the result is then:

```
    population.served      area   year
 1:               200 Cambridge Year.1
 2:               202 Cambridge Year.2
 3:               204 Cambridge Year.3
 4:               207 Cambridge Year.4
 5:                 0 Edinburgh Year.1
 6:                 0 Edinburgh Year.2
 7:                 0 Edinburgh Year.3
 8:               210 Edinburgh Year.4
 9:                 0    London Year.1
10:                 0    London Year.2
11:               206    London Year.3
12:               209    London Year.4
13:               201    Oxford Year.1
14:               203    Oxford Year.2
15:               205    Oxford Year.3
16:               208    Oxford Year.4

```