-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathREADME.Rmd
398 lines (357 loc) · 13.6 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "figure/",
fig.height = 1
)
```
# BuenColors
A package that facilitates nice colors created for the [Buenrostro Lab](https://buenrostrolab.com). The base of the package including some divergent color schemes were taken from the [wesanderson](https://github.com/karthik/wesanderson) package. This README provides a quick overview of how to use the color schemes with ggplot2 and which palettes are available.
## Installation
```R
devtools::install_github("caleblareau/BuenColors")
```
## Color Palettes
```{r, library_dummy, message=FALSE, warning = FALSE}
library(BuenColors)
```
With the library loaded, just type this to get either the `continuous` or
`discrete` (by default) palette printed in your `plot` console.
```{r, example}
jdb_palette("FantasticFox")
jdb_palette("aqua_brick", type = "continuous")
```
### Here are all the names that are available...
```{r, palettes_dummy, echo = FALSE}
sort(names(jdb_palettes))
```
## Color Maps
To keep consistent color designations, one can use the `color_map` function to link features to their
specific hex color annoations. For example,
```{r, hsc1, echo = TRUE}
jdb_color_map(c("HSC"))
```
returns the hex code associated with `HSC` in the Buenrostro Lab paradigm. This function may be applied
over multiple features--
```{r, hsc2, echo = TRUE}
jdb_color_map(c("HSC", "CMP", "HSC"))
```
and will error out when a feature is not recognized--
```{r, hsc0, echo = TRUE, eval = FALSE}
jdb_color_map(c("WHAT"))
#> Error: all(name %in% names(jdb_color_maps)) is not TRUE
```
### Here are all the names that are available...
```{r, colmaps_dummy, echo = FALSE}
sort(names(jdb_color_maps))
```
### Here are what the mappings look like...
```{r, colormaps, fig.height = 10, echo = FALSE}
df <- data.frame(names = names(jdb_color_maps),
jdb_color_maps = unname(jdb_color_maps), stringsAsFactors = FALSE)
ggplot(df, aes(x = names, y = -1, fill = names)) +
geom_bar(stat = "identity") + pretty_plot(fontsize = 20) +
scale_fill_manual(values = jdb_color_maps) + coord_flip() +
theme(legend.position = "none")+
scale_y_continuous(expand = c(0, 0)) +
labs(x = NULL, y = NULL, title = "Buenrostro Lab Cell Schemes") +
theme(axis.title.x=element_blank(), axis.text.x=element_blank(),
axis.ticks.x=element_blank(), panel.border = element_blank())
```
## ggplot example
To coordinate a ggplot feature (e.g. data point in a scatter plot) with a particular color, [this post](https://www.biostars.org/p/204891/) was a life-saver. Specifically, we'll use a named vector
to coordinate the discrete values. Here's an example--
```{r, colormapPlotExample, fig.height = 5, echo = TRUE}
xy <- 1:7
cell <- c("GMP-A", "Ery", "CD4", "Ery", "LMPP", "ERY", "MEP")
df <- data.frame(
xy = xy,
cell = cell, stringsAsFactors = FALSE
)
ggplot(df, aes(x = xy, y = xy, color = cell)) +
geom_point(size = 10) + pretty_plot() +
scale_color_manual(values = jdb_color_maps)
```
**P.S.**-- this call will return a blank color for features that are not found in the color map ("ERY" in this example).
### Important Note on color mappings...
The above `ggplot` command works because `jdb_color_maps` (with an 's') exists as a named vector in the `BuenColors` NAMESPACE. The provided function (`jdb_color_map`) does not have an 's' by the way. This same syntax of supplying a named vector should work for all discrete color scale functionalities in `ggplot`.
# Discrete colors
The trick here is to use `scale_color_manual` like it is shown here--
```{r, discrete, fig.height = 3}
library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point() + pretty_plot() +
scale_color_manual(values = jdb_palette("brewer_spectra"))
```
# Continuous fill
The trick here is to use `scale_color_gradientn` like it is shown here--
```{r, ggplotcont, fig.height = 3}
df <- data.frame(x = rnorm(1000), y = 0)
ggplot(df, aes(x=x, y=y, colour=x)) + geom_point() +
scale_color_gradientn(colors = jdb_palette("flame_light")) +
pretty_plot()
```
# Density Plot
Best way that I've found to make the density color
function represented in the points. Thanks to
[Kamil Slowikowski](http://slowkow.com/notes/ggplot2-color-by-density/) for
figuring this out.
```{r, ggplotdensty, fig.height = 5}
dat <- data.frame(
x = c(
rnorm(1e4, mean = 0, sd = 0.1),
rnorm(1e3, mean = 0, sd = 0.1)
),
y = c(
rnorm(1e4, mean = 0, sd = 0.1),
rnorm(1e3, mean = 0.1, sd = 0.2)
)
)
dat$density <- get_density(dat$x, dat$y)
ggplot2::ggplot(dat) + geom_point(aes(x, y, color = density)) +
scale_color_gradientn(colors = jdb_palette("solar_extra")) +
pretty_plot()
```
# Shuffle Plot Order
Quick wrapper using `shuf` to change the order of plotting points
(to a random presentation) to avoid hiding effects.
```{r, tsne, fig.height = 5}
tdf<-paste(system.file('rds',package='BuenColors'),'basicTSNE.rds',sep='/')
df <- readRDS(tdf)
ggplot(shuf(df)) + geom_point(aes(X1, X2, color = counts)) +
scale_color_gradientn(colors = jdb_palette("solar_extra")) +
pretty_plot()
```
```{r, makeEverything, echo = FALSE, eval = FALSE}
# Generate this
write.table(data.frame('jdb_palette("',sort(names(jdb_palettes)), '", type = "continuous")'), file = "choices_cont.txt",col.names = FALSE, quote = FALSE, row.names = FALSE, sep = "")
write.table(data.frame('jdb_palette("',sort(names(jdb_palettes)), '")'), file = "choices_disc.txt",col.names = FALSE, quote = FALSE, row.names = FALSE, sep = "")
```
## Continuous Colors
Here's what each palette looks like on a continuous scale.
```{r, printCont, echo = FALSE}
jdb_palette("algae_earth", type = "continuous")
jdb_palette("aqua_brick", type = "continuous")
jdb_palette("aqua_tan", type = "continuous")
jdb_palette("berry", type = "continuous")
jdb_palette("blue_cyan", type = "continuous")
jdb_palette("BottleRocket", type = "continuous")
jdb_palette("BottleRocket2", type = "continuous")
jdb_palette("brewer_blue", type = "continuous")
jdb_palette("brewer_celsius", type = "continuous")
jdb_palette("brewer_fire", type = "continuous")
jdb_palette("brewer_green", type = "continuous")
jdb_palette("brewer_heat", type = "continuous")
jdb_palette("brewer_jamaica", type = "continuous")
jdb_palette("brewer_marine", type = "continuous")
jdb_palette("brewer_orange", type = "continuous")
jdb_palette("brewer_purple", type = "continuous")
jdb_palette("brewer_red", type = "continuous")
jdb_palette("brewer_spectra", type = "continuous")
jdb_palette("brewer_violet", type = "continuous")
jdb_palette("brewer_yes", type = "continuous")
jdb_palette("calma_azules", type = "continuous")
jdb_palette("calma_bosque", type = "continuous")
jdb_palette("calma_manudo", type = "continuous")
jdb_palette("calma_marino", type = "continuous")
jdb_palette("calma_morado", type = "continuous")
jdb_palette("calma_musgos", type = "continuous")
jdb_palette("Cavalcanti", type = "continuous")
jdb_palette("Chevalier", type = "continuous")
jdb_palette("china_basics", type = "continuous")
jdb_palette("china_dragon", type = "continuous")
jdb_palette("china_novice", type = "continuous")
jdb_palette("china_ranges", type = "continuous")
jdb_palette("china_sunset", type = "continuous")
jdb_palette("china_theory", type = "continuous")
jdb_palette("china_weirdo", type = "continuous")
jdb_palette("citric", type = "continuous")
jdb_palette("citric_yellow", type = "continuous")
jdb_palette("citrus", type = "continuous")
jdb_palette("corona", type = "continuous")
jdb_palette("cyan_brick", type = "continuous")
jdb_palette("cyan_green", type = "continuous")
jdb_palette("cyan_pink", type = "continuous")
jdb_palette("cyan_purple", type = "continuous")
jdb_palette("cyan_tan", type = "continuous")
jdb_palette("cyan_violet", type = "continuous")
jdb_palette("Darjeeling", type = "continuous")
jdb_palette("Darjeeling2", type = "continuous")
jdb_palette("dark_blue", type = "continuous")
jdb_palette("dark_citrus", type = "continuous")
jdb_palette("dark_cyan", type = "continuous")
jdb_palette("dark_violet", type = "continuous")
jdb_palette("dusk_dawn", type = "continuous")
jdb_palette("FantasticFox", type = "continuous")
jdb_palette("flame_artic", type = "continuous")
jdb_palette("flame_blind", type = "continuous")
jdb_palette("flame_flame", type = "continuous")
jdb_palette("flame_light", type = "continuous")
jdb_palette("flame_macaw", type = "continuous")
jdb_palette("flame_polar", type = "continuous")
jdb_palette("flame_volts", type = "continuous")
jdb_palette("flame_watts", type = "continuous")
jdb_palette("flame_weird", type = "continuous")
jdb_palette("flame_wings", type = "continuous")
jdb_palette("forest", type = "continuous")
jdb_palette("forest_citric", type = "continuous")
jdb_palette("forest_yellow", type = "continuous")
jdb_palette("GrandBudapest", type = "continuous")
jdb_palette("GrandBudapest2", type = "continuous")
jdb_palette("horizon", type = "continuous")
jdb_palette("horizon_extra", type = "continuous")
jdb_palette("lawhoops", type = "continuous")
jdb_palette("Moonrise1", type = "continuous")
jdb_palette("Moonrise2", type = "continuous")
jdb_palette("Moonrise3", type = "continuous")
jdb_palette("ocean_aqua", type = "continuous")
jdb_palette("ocean_brick", type = "continuous")
jdb_palette("ocean_citrus", type = "continuous")
jdb_palette("ocean_earth", type = "continuous")
jdb_palette("ocean_green", type = "continuous")
jdb_palette("ocean_pink", type = "continuous")
jdb_palette("ocean_red", type = "continuous")
jdb_palette("ocean_teal", type = "continuous")
jdb_palette("purple_baby", type = "continuous")
jdb_palette("purple_pink", type = "continuous")
jdb_palette("Royal1", type = "continuous")
jdb_palette("Royal2", type = "continuous")
jdb_palette("Rushmore", type = "continuous")
jdb_palette("samba_color", type = "continuous")
jdb_palette("samba_light", type = "continuous")
jdb_palette("samba_night", type = "continuous")
jdb_palette("solar_basic", type = "continuous")
jdb_palette("solar_blues", type = "continuous")
jdb_palette("solar_extra", type = "continuous")
jdb_palette("solar_flare", type = "continuous")
jdb_palette("solar_glare", type = "continuous")
jdb_palette("solar_rojos", type = "continuous")
jdb_palette("teal_orange", type = "continuous")
jdb_palette("teal_violet", type = "continuous")
jdb_palette("white_grove", type = "continuous")
jdb_palette("white_jungle", type = "continuous")
jdb_palette("white_mango", type = "continuous")
jdb_palette("white_orange", type = "continuous")
jdb_palette("white_tango", type = "continuous")
jdb_palette("wolfgang_basic", type = "continuous")
jdb_palette("wolfgang_extra", type = "continuous")
jdb_palette("Zissou", type = "continuous")
```
## Discrete colors
Here are the discrete color units that go into each scale. If n is small and discrete, note
that the colors that are selected are read from left to right.
```{r, printDiscrete, echo = FALSE}
jdb_palette("algae_earth")
jdb_palette("aqua_brick")
jdb_palette("aqua_tan")
jdb_palette("berry")
jdb_palette("blue_cyan")
jdb_palette("BottleRocket")
jdb_palette("BottleRocket2")
jdb_palette("brewer_blue")
jdb_palette("brewer_celsius")
jdb_palette("brewer_fire")
jdb_palette("brewer_green")
jdb_palette("brewer_heat")
jdb_palette("brewer_jamaica")
jdb_palette("brewer_marine")
jdb_palette("brewer_orange")
jdb_palette("brewer_purple")
jdb_palette("brewer_red")
jdb_palette("brewer_spectra")
jdb_palette("brewer_violet")
jdb_palette("brewer_yes")
jdb_palette("calma_azules")
jdb_palette("calma_bosque")
jdb_palette("calma_manudo")
jdb_palette("calma_marino")
jdb_palette("calma_morado")
jdb_palette("calma_musgos")
jdb_palette("Cavalcanti")
jdb_palette("Chevalier")
jdb_palette("china_basics")
jdb_palette("china_dragon")
jdb_palette("china_novice")
jdb_palette("china_ranges")
jdb_palette("china_sunset")
jdb_palette("china_theory")
jdb_palette("china_weirdo")
jdb_palette("citric")
jdb_palette("citric_yellow")
jdb_palette("citrus")
jdb_palette("corona")
jdb_palette("cyan_brick")
jdb_palette("cyan_green")
jdb_palette("cyan_pink")
jdb_palette("cyan_purple")
jdb_palette("cyan_tan")
jdb_palette("cyan_violet")
jdb_palette("Darjeeling")
jdb_palette("Darjeeling2")
jdb_palette("dark_blue")
jdb_palette("dark_citrus")
jdb_palette("dark_cyan")
jdb_palette("dark_violet")
jdb_palette("dusk_dawn")
jdb_palette("FantasticFox")
jdb_palette("flame_artic")
jdb_palette("flame_blind")
jdb_palette("flame_flame")
jdb_palette("flame_light")
jdb_palette("flame_macaw")
jdb_palette("flame_polar")
jdb_palette("flame_volts")
jdb_palette("flame_watts")
jdb_palette("flame_weird")
jdb_palette("flame_wings")
jdb_palette("forest")
jdb_palette("forest_citric")
jdb_palette("forest_yellow")
jdb_palette("GrandBudapest")
jdb_palette("GrandBudapest2")
jdb_palette("horizon")
jdb_palette("horizon_extra")
jdb_palette("lawhoops")
jdb_palette("Moonrise1")
jdb_palette("Moonrise2")
jdb_palette("Moonrise3")
jdb_palette("ocean_aqua")
jdb_palette("ocean_brick")
jdb_palette("ocean_citrus")
jdb_palette("ocean_earth")
jdb_palette("ocean_green")
jdb_palette("ocean_pink")
jdb_palette("ocean_red")
jdb_palette("ocean_teal")
jdb_palette("purple_baby")
jdb_palette("purple_pink")
jdb_palette("Royal1")
jdb_palette("Royal2")
jdb_palette("Rushmore")
jdb_palette("samba_color")
jdb_palette("samba_light")
jdb_palette("samba_night")
jdb_palette("solar_basic")
jdb_palette("solar_blues")
jdb_palette("solar_extra")
jdb_palette("solar_flare")
jdb_palette("solar_glare")
jdb_palette("solar_rojos")
jdb_palette("teal_orange")
jdb_palette("teal_violet")
jdb_palette("white_grove")
jdb_palette("white_jungle")
jdb_palette("white_mango")
jdb_palette("white_orange")
jdb_palette("white_tango")
jdb_palette("wolfgang_basic")
jdb_palette("wolfgang_extra")
jdb_palette("Zissou")
```