What is this

An R package to generate palettes based on famous paintings from the Rijksmuseum, using the fantastic Rijksmuseum API.

# Install the development version:
devtools::install_github("vankesteren/rijkspalette")

How to use

Let’s make a barplot using a palette based on Vermeer’s famous painting of a woman reading a letter. The rijksPalette() function queries the collection of paintings of the Rijksmuseum in Amsterdam.

library(rijkspalette)
letter <- rijksPalette("Vermeer Letter")
letter

A 16-bit impression of the palette is shown in the R console.

console

Let’s look at the palette a bit better:

plot(letter)

vermeer

Now we can make a plot using the palette from these colours.

barplot(iris$Sepal.Length,
        col = letter$palette(3)[iris$Species],
        border = NA, space = 0,
        main = "Sepal length of 3 iris species")

iris

Note that the palette() function performs interpolation: you can generate any number of colours!

barplot(rep(1, 1500),
        col = letter$palette(1500),
        border = NA, space = 0,
        axes = FALSE, asp = 1)

continuous

Try it out for yourself! Post your palette on twitter with the #rijkspalette hashtag 👍


spacer

Details: tuning, exploring, and clustering

The palette works well for the above image. However, when a painter uses many colours, some prominent colours may be skipped:

appel5 <- rijksPalette("Karel Appel")
plot(appel5)

appel5

Here, the quite prominent red colour is skipped. Luckily, we can tune both the number of colours and the brightness of those colours:

appel7 <- tune(appel5, brightness = 0.85, k = 7)
plot(appel7)

appel5

That’s better. But why? The explore() function can give us more detail:

explore(appel)

explore

Here, we see the colours in the image plotted on the a*b* space. The white squares are the cluster centroids used to generate the palette. Note that the two quite distinct arms in the top of the plot belong to the same cluster. By increasing the number of clusters (the number of colours in the palette), we can fix this issue:

explore7

The better coverage of the colour space indicates that 7 clusters is better than 5. The k argument in the tune() function takes care of that.

To access the individual colours, use the cols slot:

appel$cols

[1] "#A8402D" "#969D4C" "#B5BDAC" "#7D817A" "#336D7F" "#235B6D" "#303344"

As before, the palette slot is a colorRampPalette function to be used in plots:

barplot(1/sqrt(1:15), col = appel$palette(15))

barplot