Learn R Programming

cartography (version 1.3.0)

carto.pal: Build Cartographic Palettes

Description

Builds sequantial and diverging color palettes. Diververging color palettes can be dissymetric (different number of colors in each of the two gradients)

Usage

carto.pal(pal1, n1, pal2 = NULL, n2 = NULL, middle = FALSE, transparency = FALSE)

Arguments

pal1
name of the color gradiant (see Details).
n1
number of colors (up to 20)
pal2
name of the color gradiant (see Details).
n2
number of colors (up to 20)
middle
a logical value. If TRUE, a neutral color ("#F6F6F6", almost white) between two gradients is added.
transparency
a logical value. If TRUE, contrasts are enhenced by adding an opacity variation.

Value

A vector of colors is returned.

Details

Available palettes are: "blue.pal", "orange.pal", "red.pal", "brown.pal", "green.pal", "purple.pal" "pink.pal", "wine.pal", "grey.pal", "turquoise.pal", "sand.pal", "taupe.pal", "kaki.pal" , "harmo.pal".

See Also

display.carto.pal, display.carto.all

Examples

Run this code
# Simple gradient: blue
carto.pal(pal1 = "blue.pal" ,n1 = 20)

# Double gradient: blue & red
carto.pal(pal1 = "blue.pal", n1 = 10, pal2 = "red.pal", n2 = 10)

# Adding a neutral color
carto.pal(pal1 = "blue.pal", n1 = 10, pal2 = "red.pal", n2 = 10, middle = TRUE)

# Enhancing contrasts with transparency
carto.pal(pal1="blue.pal", n1 = 10, pal2 = "red.pal", n2 = 10, middle = TRUE,
          transparency = TRUE)

# The double gradient can be asymetric
carto.pal(pal1 = "blue.pal", n1 = 5, pal2 = "red.pal", n2 = 15, middle = TRUE,
          transparency = TRUE)

# Build and display a palette
mypal <- carto.pal(pal1 = "blue.pal", n1 = 5, pal2 = "red.pal", n2 = 15,
                   middle = TRUE, transparency = TRUE)
k <- length(mypal)
image(1:k, 1, as.matrix(1:k), col =mypal, xlab = paste(k," classes",sep=""),
      ylab = "", xaxt = "n", yaxt = "n",bty = "n")

Run the code above in your browser using DataLab