Generate a Monochromatic Palette

Generate a palette of tints, shades or both from a single colour.


lifecycle Travis buildstatus AppVeyor buildstatus Coveragestatus License:MIT CRANstatus

Introduction

tinter provides a simple way to generate monochromatic palettes. Easily define:

  • palette direction (“shades”, “tints”, or “both”).
  • number of colours to generate on either side (steps).
  • number of colours to remove from extreme end(s) of palette (e.g. default crop = 1 eliminates black and white).
  • darker or lighter output (adjust).
library(tinter)
hex <- "#a6c2d8"

tinter(hex)
#> [1] "#EDF2F7" "#DBE6EF" "#C9DAE7" "#B7CEDF" "#A6C2D8" "#849BAC" "#637481"
#> [8] "#424D56" "#21262B"

tinter(hex, direction = "tints")

tinter(hex, steps = 10)

tinter(hex, steps = 10, crop = 7)

tinter(hex, steps = 10, crop = 7, adjust = 0.4)

Create a choropleth map

library(ggplot2)
library(sf)
 
nc <- st_read(system.file(package = "sf", "shape/nc.shp"))
 
ggplot(data = nc) +
  geom_sf(aes(fill = AREA), colour = "white", lwd = 0.05) +
  # colours from tinter
  scale_fill_gradientn(colours = tinter(hex)) +
  theme_void() +
  coord_sf(datum = NA)

Doesn’t this already exist?

tinter just simplifies a task usually done with grDevices. It’s default is to remove black and white from the palette.

tinter("blue")
#> [1] "#CCCCFF" "#9999FF" "#6666FF" "#3333FF" "#0000FF" "#0000CC" "#000099"
#> [8] "#000065" "#000032"
 
### ------ is identical to
 
grDevices::colorRampPalette(colors = c("white", "blue", "black"))(11)[-(c(1, 11))]
#> [1] "#CCCCFF" "#9999FF" "#6565FF" "#3232FF" "#0000FF" "#0000CB" "#000098"
#> [8] "#000065" "#000032"
tinter("blue", direction = "shades")
#> [1] "#0000FF" "#0000CC" "#000099" "#000065" "#000032"
 
### --- is identical to
 
grDevices::colorRampPalette(colors = c("blue", "black"))(6)[-6]
#> [1] "#0000FF" "#0000CC" "#000099" "#000065" "#000032"
tinter("blue", crop = 2)
#> [1] "#9999FF" "#6666FF" "#3333FF" "#0000FF" "#0000CC" "#000099" "#000065"
 
### --- is identical to
 
grDevices::colorRampPalette(colors = c("white", "blue", "black"))(11)[-(c(1:2, 10:11))]
#> [1] "#9999FF" "#6565FF" "#3232FF" "#0000FF" "#0000CB" "#000098" "#000065"

Installation

To install the latest development version from GitHub

install.packages("devtools")
devtools::install_github("poissonconsulting/err")
devtools::install_github("poissonconsulting/checkr")
devtools::install_github("poissonconsulting/tinter")

To install the latest development version from the Poisson drat repository

install.packages("drat")
drat::addRepo("poissonconsulting")
install.packages("tinter")

Contribution

Please report any issues.

Pull requests are always welcome.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

News

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("tinter")

0.0.1 by Sebastian Dalgarno, 3 months ago


https://github.com/poissonconsulting/tinter


Report a bug at https://github.com/poissonconsulting/tinter/issues


Browse source code at https://github.com/cran/tinter


Authors: Sebastian Dalgarno [aut, cre] , Joe Thorley [ctb]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports checkr, grDevices

Suggests graphics, covr, testthat


See at CRAN