0

I am attempting to find the color palette of an image. I have found a handful of code examples, however, have run into issues with finding packages that are supported on the current R version (3.5.2). I have not been able to install the required packages (readJPEG, dim, etc) and was wondering if there is a work around or updated versions available. I have been following paletteR, link below. Thank you for any assistance.

https://datascienceplus.com/how-to-use-paletter-to-automagically-build-palettes-from-pictures/

Sarah
  • 1

1 Answers1

1

There are several packages that can do that. I personally like cuttlefish:

# devtools::install_github("jcbain/cuttlefish")
colours_vector <- cuttlefish::create_palette("example.jpg", n = 32)

Here is a quick example using the Mona Lisa as source for our palette:

library(ggplot2)
mona_lisa <- 
  "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/800px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg"

colours_vector_mlisa <- cuttlefish::create_palette(mona_lisa, n = 7)
ggplot(mpg, aes(displ, hwy, colour = class)) + 
  geom_point() +
  scale_color_manual(values = colours_vector_mlisa)

enter image description here

JBGruber
  • 11,727
  • 1
  • 23
  • 45