Here is how to install and load the R package:
Find the color palette of particular parts of the world
This package does the following:
- Downloads a image of a particular place from google earth/maps. Google uses a variety of sources for these images depending on the place and zoom
- Translates the colors into a perceptually uniform color space--CIE LAB
- Runs a clustering method (currently supporting choice of two different methods)
- Returns a color pallette
There is only one function
get_earthtones. Here is how you use it, in this case for the grand canyon:
get_earthtones(latitude = 36.094994, longitude=-111.837962, zoom=12, number_of_colors=8)
number_of_colors corresponds to how many colors you want back. The
zoom value is passed to
ggmap::get_map--essentially larger values zoom closer to the target lat+long.
Maybe desert colors aren't your thing: you want a color scheme drawn from tropical reefs and lagoons. How about the Bahamas?
get_earthtones(latitude = 24.2, longitude=-77.88, zoom=11, number_of_colors=5)
Just pick your favorite place in the world, and find out the major colors
Here is San Francisco:
get_earthtones(latitude = 37.89, longitude=-122.28, zoom=11, number_of_colors=12)
or the Golden Gate Bridge:
get_earthtones(latitude = 37.81391, longitude=-122.478289, zoom=19, number_of_colors=12)
or Sydney Opera House :
get_earthtones(latitude = -33.85745, longitude=151.214722, zoom=17, number_of_colors=10)
If you want to actually use the color scheme for another visualization and not just plot pretty picturs, there is a switch in the
get_earthtones function: just add
include.map=FALSE to the function call, and the function will only return the color palette for later use:
if(!require(ggplot2)) install.packages("ggplot2") bahamas_colors <- get_earthtones(latitude = 24.2, longitude=-77.88, zoom=11, number_of_colors=3,include.map=FALSE) ggplot(iris, aes(x=Petal.Length, y=Petal.Width, col=Species))+ geom_point(size = 2.5)+ scale_color_manual(values = bahamas_colors)+ theme_bw()
And now Fisher's irises are colored Bahamas-style. However, data from two of the three iris species was actually collected by a botanist named Edgar Anderson from the Gaspé Peninsula in Quebec, so it might be better to use a color scheme from there for those two species.
iris.from.gaspe <- subset(iris, iris$Species!="virginica") get_earthtones(latitude = 48.7709, longitude=-64.660939,zoom=9,number_of_colors = 2)
gaspe <- get_earthtones(latitude = 48.7709, longitude=-64.660939 ,zoom=9, number_of_colors = 2,include.map=FALSE) ggplot(iris.from.gaspe, aes(x=Petal.Length, y=Petal.Width,col=Species))+ geom_point(size = 2.5)+ scale_color_manual(values = gaspe)+ theme_bw()
Some notes on clustering methods
There are lots of ways to do the clustering in genearl and also in this particular case. The default is pam algorithm (for reasons explained below) but there is also k-means, which is a classic clustering method and is a bit simpler and faster.
Here is the k-means result for the bahamas:
get_earthtones(latitude = 24.2, longitude=-77.88, zoom=11, number_of_colors=5, method="kmeans")
and here is the pam one
get_earthtones(latitude = 24.2, longitude=-77.88, zoom=11, number_of_colors=5, method="pam")
The sand-color is perhaps a bit sandier with the PAM approach. This actually makes sense because the PAM method returns medoids rather than centroids so the outputs are guaranteed to be actual colors in the image. When using the k-means method, the centroid of a set of colors may actually be a color that is not itself present in the image.
There are some other cool things to do with the cool and images in the RImagePallette package. And there is a very cool blog on the colors of Antartica. And of course if you want a quirky cinematic color scheme, check out wesanderson.
If you'd like to try the most recent development version of
earthtones run this:
if(!require(devtools)) install.packages("devtools") devtools::install_github("wcornwell/earthtones")