forked from leonawicz/trekcolors
-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
194 lines (144 loc) · 7.72 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE, comment = "#>", fig.path = "man/figures/README-",
fig.height = 3, out.width = "100%", dpi = 150, message = FALSE,
warning = FALSE, error = FALSE, dev.args = list(type = "cairo")
)
```
# trekcolors <img src="man/figures/logo.png" style="margin-left:10px;margin-bottom:5px;" width="120" align="right">
**Author:** [Matthew Leonawicz](https://github.com/leonawicz) <a href="https://orcid.org/0000-0001-9452-2771" target="orcid.widget">
<image class="orcid" src="https://members.orcid.org/sites/default/files/vector_iD_icon.svg" height="16"></a>
<br/>
**License:** [MIT](https://opensource.org/licenses/MIT)<br/>
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/)
[![Travis build status](https://travis-ci.org/leonawicz/trekcolors.svg?branch=master)](https://travis-ci.org/leonawicz/trekcolors)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/leonawicz/trekcolors?branch=master&svg=true)](https://ci.appveyor.com/project/leonawicz/trekcolors)
[![Codecov test coverage](https://codecov.io/gh/leonawicz/trekcolors/branch/master/graph/badge.svg)](https://codecov.io/gh/leonawicz/trekcolors?branch=master)
[![CRAN status](http://www.r-pkg.org/badges/version/trekcolors)](https://cran.r-project.org/package=trekcolors)
[![CRAN downloads](http://cranlogs.r-pkg.org/badges/grand-total/trekcolors)](https://cran.r-project.org/package=trekcolors)
[![Github Stars](https://img.shields.io/github/stars/leonawicz/trekcolors.svg?style=social&label=Github)](https://github.com/leonawicz/trekcolors)
The `trekcolors` package provides a collection of color palettes based on Star Trek. It also offers functions for custom palettes and `scale_*` functions for use with `ggplot2`.
## Installation
Install the CRAN release of `trekcolors` with
```r
install.packages("trekcolors")
```
Install the development version from GitHub with
```r
# install.packages("remotes")
remotes::install_github("leonawicz/trekcolors")
```
## Examples
### Basics
```{r ex1}
library(trekcolors)
library(ggplot2)
trek_pal("starfleet")
trek_pal("lcars_2357")
lcars_pal("2357") # there are some special functions for LCARS colors
```
Preview the `starfleet` and `lcars_2357` palettes.
```{r ex2}
view_trek_pals(c("starfleet", "lcars_2357"))
```
### Scale functions for use with ggplot2
```{r ex3}
p <- ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
geom_point(size = 5, alpha = 0.75)
p + scale_color_trek() # starfleet is default palette
p <- ggplot(diamonds, aes(carat, price, color = clarity)) +
geom_point()
p + scale_color_lcars("2357") # equivalent to scale_color_trek("lcars_2357")
p <- ggplot(diamonds, aes(carat, stat(count), fill = cut)) +
geom_density(position = "fill")
p + scale_fill_trek("klingon")
p + scale_fill_trek("romulan")
p + scale_fill_trek("andorian")
p <- ggplot(diamonds, aes(carat, stat(count), fill = cut)) +
geom_density(position = "fill")
p + scale_fill_lcars("2357")
p + scale_fill_lcars1("atomic-tangerine", dark = TRUE)
p + scale_fill_lcars2("pale-canary", "danub")
d <- diamonds[diamonds$cut >= "Very Good", ]
p <- ggplot(d, aes(carat, stat(count), fill = cut)) +
geom_density(position = "fill")
p + scale_fill_trek("starfleet")
```
### Palettes with named colors
The four LCARS palettes that have a year in their series name are special in that these official standard LCARS colors have formal names.
```{r ex4}
# lcars_pals() # print list of all LCARS palettes
lcars_colors() # full set of unique names across the four palettes
lcars_2357() # specific color series; also 2369, 2375, 2379
lcars_2357("lilac", "mariner") # select by name
```
### Custom palettes
In addition to these and all the other predefined palettes, custom palettes can be constructed using official LCARS color names. This is like `colorRampPalette` but with the ability to recognize official LCARS color names. This functionality was leveraged by `scale_color_lcars1` and `scale_color_lcars2` seen above when making sequential or divergent palettes based on specific LCARS colors for use with ggplot.
```{r ex5}
lcars_custom_pal <- lcars_colors_pal(c("pale-canary", "eggplant"))
lcars_custom_pal(8)
p <- ggplot(diamonds, aes(carat, stat(count), fill = cut)) +
geom_density(position = "fill")
p + scale_fill_lcars2("pale-canary", "danub")
# p + scale_fill_manual(values = lcars_custom_pal(8)) # equivalent
p + scale_fill_lcars2("pale-canary", "danub", divergent = TRUE)
p + scale_fill_lcars2("pale-canary", "danub", dark = TRUE, divergent = TRUE)
```
### All predefined palettes
```{r ex6, fig.width=6, fig.height=8}
# See available palette names
trek_pal()
# view all predefined palettes
view_trek_pals()
```
## Packages in the trekverse
<div class="row">
<div class="col-sm-2">
<a href="https://github.com/leonawicz/rtrek"><img src="https://raw.githubusercontent.com/leonawicz/rtrek/master/man/figures/logo.png" style="margin-right:20px;margin-bottom:0;" width="120" align="left"></a>
</div>
<div class="col-sm-10">
<h4 style="padding:30px 0 0 0;margin-top:5px;margin-bottom:5px;"><a href="https://github.com/leonawicz/rtrek">rtrek</a>: The core Star Trek package</h4>
Datasets related to Star Trek, API wrappers to external data sources, and more.
</div></div>
<br/>
<div class="row">
<div class="col-sm-2">
<a href="https://github.com/leonawicz/lcars"><img src="https://raw.githubusercontent.com/leonawicz/lcars/master/man/figures/logo.png" style="margin-right:20px;margin-bottom:0;" width="120" align="left"></a>
</div>
<div class="col-sm-10">
<h4 style="padding:30px 0 0 0;margin-top:5px;margin-bottom:5px;"><a href="https://github.com/leonawicz/lcars">lcars</a>: LCARS aesthetic for Shiny</h4>
Create Shiny apps based on the Library Computer Access/Retrieval System (LCARS).
</div></div>
<br/>
<div class="row">
<div class="col-sm-2">
<a href="https://github.com/leonawicz/trekcolors"><img src="https://raw.githubusercontent.com/leonawicz/trekcolors/master/man/figures/logo.png" style="margin-right:20px;margin-bottom:0;" width="120" align="left"></a>
</div>
<div class="col-sm-10">
<h4 style="padding:30px 0 0 0;margin-top:5px;margin-bottom:5px;"><a href="https://github.com/leonawicz/trekcolors">trekcolors</a>: A color palette package</h4>
Predefined and customizable Star Trek themed color palettes and related functions.
</div></div>
<br/>
<div class="row">
<div class="col-sm-2">
<a href="https://github.com/leonawicz/trekfont"><img src="https://raw.githubusercontent.com/leonawicz/trekfont/master/man/figures/logo.png" style="margin-right:20px;margin-bottom:0;" width="120" align="left"></a>
</div>
<div class="col-sm-10">
<h4 style="padding:30px 0 0 0;margin-top:5px;margin-bottom:5px;"><a href="https://github.com/leonawicz/trekfont">trekfont</a>: A fonts package</h4>
True (Trek) type fonts to style your Star Trek themed graphics text.
</div></div>
<br>
## Citation
Matthew Leonawicz (2020). trekcolors: Star Trek Color Palettes. R package version 0.1.2. https://CRAN.R-project.org/package=trekcolors
## Contribute
Contributions are welcome. Contribute through GitHub via pull request. Please create an issue first if it is regarding any substantive feature add or change.
If you enjoy my open source R community contributions, please consider a donation :).
* [Buy me a coffee in Ko-fi](https://ko-fi.com/leonawicz)
* `leonawicz.crypto`
* `mfl$payid.crypto.com`
---
Please note that the `trekcolors` project is released with a [Contributor Code of Conduct](https://github.com/leonawicz/trekcolors/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.