-
Notifications
You must be signed in to change notification settings - Fork 6
/
README.Rmd
executable file
·228 lines (171 loc) · 7.68 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
---
title: "cptcity package"
author: "Sergio Ibarra-Espinosa"
date: "`r Sys.Date()`"
output: github_document
always_allow_html: true
---
![](https://i.imgur.com/4v9WMQv.gif)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/ibarraespinosa/cptcity?branch=master&svg=true)](https://ci.apalettepveyor.com/project/ibarraespinosa/cptcity)
[![DOI](https://zenodo.org/badge/120517547.svg)](https://zenodo.org/badge/latestdoi/120517547)
[![Coverage status](https://codecov.io/gh/ibarraespinosa/cptcity/branch/master/graph/badge.svg)](https://codecov.io/github/ibarraespinosa/cptcity?branch=master)
[![](http://cranlogs.r-pkg.org/badges/cptcity)](http://cran.rstudio.com/web/packages/cptcity/index.html)
[![Rdoc](http://www.rdocumentation.org/badges/version/cptcity)](http://www.rdocumentation.org/packages/cptcity)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/cptcity)](http://cran.r-project.org/web/packages/cptcity)
[![CRAN Downloads](http://cranlogs.r-pkg.org/badges/grand-total/cptcity?color=orange)](http://cran.r-project.org/package=cptcity)
## A package to return colour gradients from CPTCITY
Colour palettes comes from http://soliton.vm.bytemark.co.uk/pub/cpt-city/index.html
Currently there are 7140 colour gradients. To se the names type `cpt_names`.
There are three functions:
1) `find_cpt`: To search the name of the colour gradient.
Example:
```{r}
library(cptcity)
find_cpt("radar")
```
2) `show_cpt`: Visually selectyour palette
```{r}
pals <- find_cpt("radar")
show_cpt(pals)
```
3) `cpt`: To return the colour gradient.
```{r}
cptcity::cpt(pal = "ncl_radar_1", n = 100)
```
4) `lucky`: To choose a random colour gradient
```{r}
cptcity::lucky(n = 100)
```
## Install and use it!
```{r eval = T}
# install.packages("cptcity") 1.0.6
# remotes::install_github("ibarraespinosa/cptcity")
packageVersion("cptcity")
library(cptcity)
image(matrix(1:100), col = cpt(pal = "mpl_inferno"))
```
## ggplot2
And you can use it ggplot2
```{r}
library(cptcity)
library(ggplot2)
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density))
```
```{r}
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density)) +
scale_fill_gradientn(colours = cpt())
```
## raster
```{r}
library(cptcity)
library(raster)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
spplot(r, scales = list(draw = T))
```
```{r}
spplot(r, scales = list(draw = T),
col.regions = rev(cpt(n = 100, pal = "colo_Skyblue2u_Gentle_Waves")))
```
## sf
```{r}
library(cptcity)
library(sf)
nc = st_read(system.file("shape/nc.shp", package="sf"))
plot(nc["AREA"], pal = cpt(colorRampPalette = T))
```
## mapview
```{r, eval = F}
library(cptcity)
library(mapview)
library(sf)
nc = st_read(system.file("shape/nc.shp", package="sf"))
mapview(nc, zcol = "AREA", col.regions = cpt(colorRampPalette = T), legend = T)
```
![](https://camo.githubusercontent.com/a56248d08ddf653a62ee23ea8855cc24e77a2c69/68747470733a2f2f692e696d6775722e636f6d2f78664f6265626e2e706e67)
## stars
```{r}
library(cptcity)
library(stars)
tif = system.file("tif/L7_ETMs.tif", package = "stars")
(x1 = read_stars(tif))
br <- classInt::classIntervals(var = x1$L7_ETMs.tif,
n = 100,
style = "sd")
plot(x1,
axes = TRUE,
lty = 0,
col = cptcity::cpt(rev = TRUE,
pal = 819,
n = length(br$brks) - 1),
key.pos = 2,
breaks = br$brks
)
```
## terra
```{r}
library(cptcity)
library(terra)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
image(r, col = cptcity::lucky())
# Colour gradient: dca_alarm.p4.0.1, number: 1115
```
# **I included a random colour gradient function!**
```r
# install.packages("cptcity")
# devtools::install_github("ibarraespinosa/cptcity")
library(cptcity)
image(matrix(1:100), col = lucky())
```
## COPYING
Each palette has a COPYING.XML files available at ins/extdata. To see each file do:
```r
library(cptcity)
files <- list.files(system.file("extdata",
package = "cptcity"),
pattern = ".xml",
recursive = T,
full.names = T)
# For instance, the COPYING files of "arendal" is
files[1]
# and the file
readLines(files[1])
1] "/usr/local/lib/R/site-library/cptcity/extdata/arendal/COPYING.xml"
[1] "<?xml version=\"1.0\"?>"
[2] "<copying>"
[3] " <authors>"
[4] " <author href=\"http://www.grida.no/graphicslib/\">"
[5] " <name>GRID-Arendal</name>"
[6] " </author>"
[7] " </authors>"
[8] " <license>"
[9] " <informal>"
[10] " Attribution and linkback requested."
[11] " </informal>"
[12] " <year>2014</year>"
[13] " <text>"
[14] " Using this graphic and referring to it is encouraged, "
[15] " and please use it in presentations, web pages, newspapers, "
[16] " blogs and reports."
[17] ""
[18] " For any form of publication, please include the link to "
[19] " this page and give the cartographer/designer credit."
[20] " </text>"
[21] " </license>"
[22] " <src>"
[23] " <format>PNG images</format>"
[24] " <link href=\"http://www.grida.no/graphicslib/detail/mean-surface-temperature_c7e4\""
[25] "\t >Temperature</link>"
[26] " <link href=\"http://www.grida.no/graphicslib/detail/arctic-topography-and-bathymetry_5645\""
[27] "\t >Arctic bathymetry</link>"
[28] " <link href=\"http://www.grida.no/graphicslib/detail/map-of-zimbabwe_36a5\""
[29] "\t >Zambezi</link>"
[30] " </src>"
[31] " <distribute>"
[32] " <qgis distribute=\"yes\" license=\"other\"/>"
[33] " </distribute>"
[34] "</copying>"
```