Skip to content

Instantly share code, notes, and snippets.

@woobe
Last active December 21, 2017 16:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woobe/da1fd5976ab7893822d4 to your computer and use it in GitHub Desktop.
Save woobe/da1fd5976ab7893822d4 to your computer and use it in GitHub Desktop.
[rPlotter]: Customised Palette Experiments

Introduction

I created a function called "extract_colours()" in my "rPlotter" package. Using this function, any image in PNG, JPG, JPEG or TIFF format can be converted into a simple colour palette.

YET, this is my very first attempt, the colours are only sorted by alphabetical order at the moment. More work is needed to arrange colours based on colour theory and other factors.

Example 1a - R Logo R Logo

Output 1a

Example 1b - Kill Bill Kill Bill

Output 1b

Example 1c - Homer Simpson Homer

Output 1c

## =============================================================================
## Customised Palette Experiments #1 - Extracting Colours from Online Images
## =============================================================================
## Install and load rPlotter (https://github.com/woobe/rPlotter)
devtools::install_github("woobe/rPlotter")
library(rPlotter)
## Example 1a - Using the R logo to create a 5-colour palette
pal_r <- extract_colours("http://developer.r-project.org/Logo/Rlogo-1.png")
par(mfrow = c(1,2))
pie(rep(1, 5), col = pal_r, main = "Palette based on R Logo")
hist(Nile, breaks = 5, col = pal_r, main = "Palette based on R Logo")
## Example 1b - Using the Kill Bill poster to create a 5-colour palette
pal_kb <- extract_colours("http://www.moviegoods.com/Assets/product_images/1010/477803.1010.A.jpg")
par(mfrow = c(1,2))
pie(rep(1, 5), col = pal_kb, main = "Palette based on Kill Bill")
hist(Nile, breaks = 5, col = pal_kb, main = "Palette based on Kill Bill")
## Example 1c - Using Homer Simpson
pal_s <- extract_colours("http://haphappy.com/wp-content/uploads/2011/03/homerbeer2.png")
par(mfrow = c(1,2))
pie(rep(1, 5), col = pal_s, main = "Palette based on Simpsons")
hist(Nile, breaks = 5, col = pal_s, main = "Palette based on Simpsons")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment