-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
298 lines (232 loc) · 8.9 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
---
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 = "images/",
out.width = "100%"
)
```
# RColorConesa
## Installation
You can install RColorConesa from CRAN repository with:
``` r
install.packages("RColorConesa")
```
or you can install the released version of RColorConesa from GitHub with:
``` r
# install.packages("devtools")
devtools::install_github("ConesaLab/RColorConesa")
```
## Information
The package RColorConesa is a color packages with different palletes inspired by the corporative image of the Conesa Lab.
![Logo ConesaLab](./images/logo_ConesaLab.png)
## Palettes
RColorConesa consists of seven main colours from which a number of different colour palettes have been created. Each palette have the continuous and the continuous form as you can see in next examples.
```{r palettes, echo=FALSE, warning=FALSE, message=FALSE}
library(RColorConesa)
library(ggplot2)
n_continuous <- 8
n_continuous_complete <- 15
```
```{r colors, echo=FALSE, warning=FALSE, eval=FALSE}
paletteList <- getConesaPalettes()
#Thank to Matifou - https://stackoverflow.com/questions/25726276/visualize-a-list-of-colors-palette-in-r
for(palette in names(paletteList)){
ncolor <- length(paletteList[palette][[1]])
colors <- paletteList[palette][[1]]
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
if(palette=="complete"){ncolor <- 15}
else{ncolor <- n_continuous}
colors <- colorConesa(ncolor, palette = palette)
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
}
```
## Palette - main
```{r palette1, echo=FALSE, fig.height=1.5}
paletteList <- getConesaPalettes()
palette = "main"
ncolor <- length(paletteList[palette][[1]])
colors <- paletteList[palette][[1]]
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
ncolor <- n_continuous
colors <- colorConesa(ncolor, palette = palette)
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
```
## Palette - nature
```{r palette2, echo=FALSE, fig.height=1.5}
paletteList <- getConesaPalettes()
palette = "nature"
ncolor <- length(paletteList[palette][[1]])
colors <- paletteList[palette][[1]]
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
ncolor <- n_continuous
colors <- colorConesa(ncolor, palette = palette)
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
```
## Palette - sunshine
```{r palette3, echo=FALSE, fig.height=1.5}
paletteList <- getConesaPalettes()
palette = "sunshine"
ncolor <- length(paletteList[palette][[1]])
colors <- paletteList[palette][[1]]
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
ncolor <- n_continuous
colors <- colorConesa(ncolor, palette = palette)
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
```
## Palette - hot
```{r palette4, echo=FALSE, fig.height=1.5}
paletteList <- getConesaPalettes()
palette = "hot"
ncolor <- length(paletteList[palette][[1]])
colors <- paletteList[palette][[1]]
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
ncolor <- n_continuous
colors <- colorConesa(ncolor, palette = palette)
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
```
## Palette - warm
```{r palette5, echo=FALSE, fig.height=1.5}
paletteList <- getConesaPalettes()
palette = "warm"
ncolor <- length(paletteList[palette][[1]])
colors <- paletteList[palette][[1]]
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
ncolor <- n_continuous
colors <- colorConesa(ncolor, palette = palette)
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
```
## Palette - cold
```{r palette6, echo=FALSE, fig.height=1.5}
paletteList <- getConesaPalettes()
palette = "cold"
ncolor <- length(paletteList[palette][[1]])
colors <- paletteList[palette][[1]]
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
ncolor <- n_continuous
colors <- colorConesa(ncolor, palette = palette)
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
```
## Palette - complete
```{r palette7, echo=FALSE, fig.height=1.5}
paletteList <- getConesaPalettes()
palette = "complete"
ncolor <- length(paletteList[palette][[1]])
colors <- paletteList[palette][[1]]
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
ncolor <- n_continuous_complete
colors <- colorConesa(ncolor, palette = palette)
palette_image <- qplot(x=1:ncolor, y = 1, fill=factor(colors, levels = colors), geom="tile") +
scale_fill_conesa(palette = palette) +
theme_void()+
theme(legend.position="none")
print(palette_image)
```
## Example - plot()
This is a basic example which shows you how to solve a common problem using the databases "iris" and the basic ploting function in R. The objetive is color by spsecie using the RcolorConesa packages.
To do this, we can use the funtion "colorConesa()" which returns a list of as many colors of you needed.
```{r example plot}
library(RColorConesa)
n_species <- length(levels(iris$Species))
colorSpecies <- colorConesa(n_species, palette = "main")
plot(x = iris$Sepal.Length, y = iris$Sepal.Width, col = colorSpecies[iris$Species], pch = 16)
legend("bottomleft", legend=c(levels(iris$Species)), col=colorSpecies, lty=1)
```
## Example - ggplot()
In case of ggplot(), if we want to plot by color it is much more easier to do with the functions "scale_color_conesa()" and "scale_fill_conesa()". We plot the same result we made before.
```{r example ggplot}
library(RColorConesa)
library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point(size = 4) +
scale_color_conesa(palette = "main")
```
A good point for the packages is you can use more colors that it already have. For example, we are going to color each Manufacturer from the dataset "mpg" from the package "ggplot2".
As you can see, the palette "complete" only have 7 colors, but it can interpolate as much as need it to fill all the categories.
```{r example ggplot - fill}
library(RColorConesa)
library(ggplot2)
mpg <- ggplot2::mpg
ggplot(mpg, aes(manufacturer, fill = manufacturer)) +
geom_bar() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_fill_conesa(palette = "complete")
```
Finally, for continuous variables, you can change the parameter continuous to True in the functions "scale_fill_conesa()" and "scale_fill_conesa()".
```{r example - continuous}
library(RColorConesa)
library(ggplot2)
df.heatmap <- expand.grid(Var1 = letters[1:15], Var2 = 1:15)
df.heatmap$score <- runif(nrow(df.heatmap), min = -5, max = 5)
ggplot(df.heatmap, aes(x = Var1, y = Var2, fill = score)) +
geom_tile() +
scale_fill_conesa(palette = "sunshine", continuous = TRUE)
```
# Contact
Note that RColorConesa can be updated. If you encounter a problem, please open an issue via GitHub or send an email to [email protected].
# Author
Pedro Salguero García - [email protected]