-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
71 lines (55 loc) · 2.19 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
output: github_document
---
Create your own color palettes and apply them in `ggplot2` in a breeze. All you
have to bring are the hex codes from you company or maybe derived from your
favorite paintings? Based on the great work by the [ochRe team](https://github.com/ropenscilabs/ochRe).
Input is either a named `list` with palettes, or a single palette. (A palette
is a character vector with hex codes of the colors.) Use `viz_pallette` to view
all the colors in a palette
```{r}
# devtools::install_github("edwinth/paletti")
library(paletti)
library(ggplot2)
viz_palette(ochre_palettes$lorikeet, "lorikeet colors")
```
From both a list of palettes and a single palette, you can create your own
`scale_fill` and `scale_color` functions to be used in `ggplot2`. If these are
based on a list of palettes, the functions will have an argument to select which
of the palettes in the list to use.
```{r}
# based on a single palette:
my_comp_fill <- get_scale_fill(get_pal(my_company_cols))
my_comp_col <- get_scale_color(get_pal(my_company_cols))
ggplot(mtcars, aes(mpg, drat, col = as.character(cyl))) +
geom_point(size = 4) +
my_comp_col()
ggplot(mtcars, aes(as.character(cyl), fill = as.character(cyl))) +
geom_bar() +
my_comp_fill()
# based on a list of palettes:
dutchmasters_fill <- get_scale_fill(get_pal(dutchmasters))
dutchmasters_col <- get_scale_color(get_pal(dutchmasters))
# scales based on lists default to the first palette
ggplot(mtcars, aes(mpg, drat, col = as.character(cyl))) +
geom_point(size = 4) +
dutchmasters_col()
ggplot(mtcars, aes(as.character(cyl), fill = as.character(cyl))) +
geom_bar() +
dutchmasters_fill("little_street")
```
The scales search for optimal contrast within the colors provided. The function
`get_hex` creates a function that returns requested hex codes. It is created
from a named palette. The returned function allows you to query with unquoted
color names.
```{r}
my_company_cols
mc_hex <- get_hex(my_company_cols)
mc_hex(yellow, blue, red)
voD_hex <- get_hex(dutchmasters$view_of_Delft)
ggplot(mtcars, aes(as.character(cyl), fill = as.character(cyl))) +
geom_bar() +
scale_fill_manual(values = voD_hex(
blue(sky), red(roofs2), yellow(quay)
))
```