https://github.com/EmilHvitfeldt/quickpalette
🏃♀️🎨 R package for quick extraction of color palettes from text and images
https://github.com/EmilHvitfeldt/quickpalette
color color-palette palettes rstats
Last synced: 4 months ago
JSON representation
🏃♀️🎨 R package for quick extraction of color palettes from text and images
- Host: GitHub
- URL: https://github.com/EmilHvitfeldt/quickpalette
- Owner: EmilHvitfeldt
- License: other
- Created: 2018-03-03T01:53:42.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T02:48:48.000Z (almost 4 years ago)
- Last Synced: 2024-11-24T01:02:34.328Z (5 months ago)
- Topics: color, color-palette, palettes, rstats
- Language: R
- Homepage:
- Size: 99.6 KB
- Stars: 28
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - EmilHvitfeldt/quickpalette - 🏃♀️🎨 R package for quick extraction of color palettes from text and images (R)
README
---
output: github_document
---```{r setup, include = FALSE}
library(knitr)
knit_hooks$set(optipng = hook_optipng)
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# quickpalette[](https://travis-ci.org/EmilHvitfeldt/quickpalette)
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](https://github.com/) with:
```{r, eval=FALSE}
# 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:
- http://colorpalettes.net/
- http://paletton.com/
- https://learnui.design/tools/data-color-picker.html
- http://tools.medialab.sciences-po.fr/iwanthue/
- http://www.color-hex.com/color-palettes/
- http://www.colourlovers.com/palettes
- https://www.w3schools.com/colors/colors_palettes.asp
- http://colorhunt.co/
- https://coolors.co/```{r}
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)
regex_palette(test2)
regex_palette(test3)
regex_palette(test4)
```### 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.
```{r testchart, echo=FALSE, message=FALSE}
library(tidyverse)
data.frame(x = 1:5,
y = rpois(n = 5, 10)) %>%
ggplot(aes(x, y, fill = factor(x))) +
geom_bar(stat = "identity") +
scale_fill_manual("legend", values = c("#DBD9BC", "#138F60", "#48A4E3", "#DE8E08", "#ECE134")) +
theme_minimal() +
labs(title = "Test chart")
```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.
```{r, message=FALSE}
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()
```