An open API service indexing awesome lists of open source software.

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!

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://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] ""
[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] ""

```