Coder Social home page Coder Social logo

kaji331 / quickpalette Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emilhvitfeldt/quickpalette

0.0 1.0 0.0 100 KB

๐Ÿƒโ€โ™€๏ธ๐ŸŽจ R package for quick extraction of color palettes from text and images

License: Other

R 100.00%

quickpalette's Introduction

quickpalette

Travis build status

The goal of quickpalette is to provide a few tools to quickly acquire new color palettes to be used in R.

Installation

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("EmilHvitfeldt/quickpalette")

Examples

regex_palette

Sometimes you see a color palette online and you want to use it in R, but it usually takes half a war to copy/paste in the individual hex values. The regex_palette function will try its best to extract a color palette from a string and return it, with the conventional leading #. Now you just copy-paste the whole thing into a string and run the function.

Example of websites where this function could be useful includes:

library(quickpalette)
test1 <- "
   shade 0 = #AA3939 = rgb(170, 57, 57) = rgba(170, 57, 57,1) = rgb0(0.667,0.224,0.224)
shade 1 = #FFAAAA = rgb(255,170,170) = rgba(255,170,170,1) = rgb0(1,0.667,0.667)
shade 2 = #D46A6A = rgb(212,106,106) = rgba(212,106,106,1) = rgb0(0.831,0.416,0.416)
shade 3 = #801515 = rgb(128, 21, 21) = rgba(128, 21, 21,1) = rgb0(0.502,0.082,0.082)
shade 4 = #550000 = rgb( 85,  0,  0) = rgba( 85,  0,  0,1) = rgb0(0.333,0,0)" 

test2 <- "
Color   Hex RGB
          #3b5998   (59,89,152)
          #8b9dc3   (139,157,195)
          #dfe3ee   (223,227,238)
          #f7f7f7   (247,247,247)
          #ffffff   (255,255,255)
          "

test3 <- "3b59988b9dc3dfe3eef7f7f7ffffff"

test4 <- "the palatte is #3472bc, #345682 then #112233 and finally #cbac43"

regex_palette(test1)
#> [1] "#AA3939" "#FFAAAA" "#D46A6A" "#801515" "#550000"
regex_palette(test2)
#> [1] "#3b5998" "#8b9dc3" "#dfe3ee" "#f7f7f7" "#ffffff"
regex_palette(test3)
#> [1] "#3b5998" "#8b9dc3" "#dfe3ee" "#f7f7f7" "#ffffff"
regex_palette(test4)
#> [1] "#3472bc" "#345682" "#112233" "#cbac43"

url_palette

Sometimes you come across a chart with a nifty looking color palettes, but the code have been left out for one reason or another. Normally you would have 2 choices, either go hunting to for the generating code in the hopes that you will be able to find the colors used or using you favorite color meter of choice you get each color individually.

Take this chart as an example, it has 5 different colors we would like to know.

Using the url_palette we we can copy url of the chart and extract the main colors using clustering algorithms. url_palette defaults to removing all grey scale pixels as they tend to not be of interest. It used a variation of Partitioning Around Medoids (PAM) clustering to ensure that the colors actually appeared in the image. Manual varying of the n_cluster argument is often necessary.

library(magrittr)
url <- "https://raw.githubusercontent.com/EmilHvitfeldt/quickpalette/master/man/figures/README-testchart-1.png"
url_palette(url, n_clusters = 5) %>%
  pals::pal.bands()

quickpalette's People

Contributors

emilhvitfeldt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.