Introduction

개발동기

  1. 기본 팔레트만 사용하는 사람들을 위해
  2. 결정장애가 있는 휴먼들을 위해

개발단계

  1. Web scrapping
  2. Assign the colors
  3. Upgrade

Development

Creat Project

devtools::create("colorhunt")

DESCRIPTION

Package: colorhunt
Type: Package
Title: A package for hunting the color instight
Version: 0.1.0
Authors@R: person("Youngjun", "Na", email = "ruminoreticulum@gmail.com", 
    role = c("aut", "cre"))
Description: The package scraping the color code from colorhunt.co, 
    then generate the palette for 'ggplot2'.
License: GPL-2
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
URL: https://github.com/adatalab/colorhunt
BugReports: https://github.com/adatalab/colorhunt/issues

Used Packages

Web Scrapping

library(rvest)
library(dplyr)

colors <- url %>%
  read_html() %>%
  html_nodes(".color") %>%
  html_children() %>%
  html_text()

return(colors)

Issues

  1. 매번 크롤링 -> 리소스를 너무 많이 잡아먹음
  2. 재현가능한 코드가 필요

color_hunt.R

LEGO 팔레트

LEGO Series

series <- unique(colorhunt::lego$name)
length(series)
## [1] 379
head(series, 20)
##  [1] "12V"                   "4 Juniors"            
##  [3] "4.5V"                  "9V"                   
##  [5] "Advent"                "Advent Sub-Set"       
##  [7] "Adventurers"           "Agents"               
##  [9] "Agori"                 "Airjitzu"             
## [11] "Airport"               "Alien Conquest"       
## [13] "Alpha Team"            "An Unexpected Journey"
## [15] "Angry Birds"           "Animals"              
## [17] "Aquanauts"             "Aquaraiders I"        
## [19] "Aquaraiders II"        "Aquasharks"

LEGO 주제별 color

colors <- colorhunt::lego %>%
  filter(color != "#FFFFFF") %>%
  filter(color != "#FCFCFC") %>%
  filter(name == series) %>%
  pull(color) %>%
  unique()

return(colors)

color_lego.R

Usage

Installation

# install.packages("remotes")
remotes::install_github("adatalab/colorhunt")

First step

color_hunt()

  • Import the colors from dribbble using color_hunt()!
  • For reproducibility, color codes are going to copy to your clipboard.
  • Paste (Ctrl + V) the color code into your script.
  • There is no need to crawling every time.

library(colorhunt)
library(ggplot2)
library(dplyr)

# Good! But, in this way, you use the resources every time.
colors <- color_hunt(url = "https://dribbble.com/shots/6393225-Iris")

# Great! Just push the Ctrl + V button!
color_hunt(url = "https://dribbble.com/shots/6393225-Iris")
colors <- c('#FFFAEB', '#538F6D', '#BA680D', '#E99E29', '#FDE75C', '#2F545F', '#CBC4C3', '#6D8A96')

iris %>%
  ggplot(aes(Sepal.Length, Sepal.Width, color = Species)) +
  geom_point(size = 2) +
  scale_color_manual(values = colors[-1]) +
  theme(
    panel.background = element_rect(fill = colors[1])
  )

color_lego()

colors <- color_lego("Ferrari")
mpg %>%
group_by(class) %>%
  summarise(displ = mean(displ)) %>%
  ggplot(aes(reorder(class, displ), displ, fill = class)) +
  geom_col() +
  scale_fill_manual(values = color_lego("Ferrari"))

Thank you!