https://github.com/ibarraespinosa/cptcity
7140 colour palletes in an R package to play!
https://github.com/ibarraespinosa/cptcity
color colors colour colour-palette colours cpt-city cptcity gradient r
Last synced: 11 months ago
JSON representation
7140 colour palletes in an R package to play!
- Host: GitHub
- URL: https://github.com/ibarraespinosa/cptcity
- Owner: ibarraespinosa
- Created: 2018-02-06T20:11:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-11-19T19:04:21.000Z (over 1 year ago)
- Last Synced: 2024-12-02T11:45:07.648Z (over 1 year ago)
- Topics: color, colors, colour, colour-palette, colours, cpt-city, cptcity, gradient, r
- Language: R
- Homepage: https://ibarraespinosa.github.io/cptcity/
- Size: 9.25 MB
- Stars: 18
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
title: "cptcity package"
author: "Sergio Ibarra-Espinosa"
date: "`r Sys.Date()`"
output: github_document
always_allow_html: true
---

[](https://ci.apalettepveyor.com/project/ibarraespinosa/cptcity)
[](https://zenodo.org/badge/latestdoi/120517547)
[](https://codecov.io/github/ibarraespinosa/cptcity?branch=master)
[](http://cran.rstudio.com/web/packages/cptcity/index.html)
[](http://www.rdocumentation.org/packages/cptcity)
[](http://cran.r-project.org/web/packages/cptcity)
[](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)
```

## 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] ""
[2] ""
[3] " "
[4] " "
[5] " GRID-Arendal"
[6] " "
[7] " "
[8] " "
[9] " "
[10] " Attribution and linkback requested."
[11] " "
[12] " 2014"
[13] " "
[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] " "
[21] " "
[22] " "
[23] " PNG images"
[24] " Temperature"
[26] " Arctic bathymetry"
[28] " Zambezi"
[30] " "
[31] " "
[32] " "
[33] " "
[34] ""
```