color_gradient: Creates a color gradient for a given vector

Description Usage Arguments Value Examples

View source: R/color_gradient.R

Description

Creates a color gradient for a given vector

Usage

1
2
color_gradient(x, colors = c("green", "yellow", "red"), x_range = NA,
  na_color = "gray", colsteps = 100)

Arguments

x

a vector of numeric values

colors

the colors for the gradient

x_range

a vector of length 2 that specifies the range of x, defaults to min/max of x

na_color

the default color if a point is outside of the x_range, defaults to gray

colsteps

the number of color-steps, defaults to 100

Value

a vector of colors of the same length as x

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
x <- c(5, 1, 2, 5, 4, 3)
color_gradient(x, c("red", "green"))
color_gradient(x, c("red", "green"), x_range = c(0, 10))

color_gradient(x, c("red", "black", "green"))

x <- seq(-10, 10, length.out = 100)
y <- abs(x^2 - 20)
plot(x, y, col = color_gradient(y), pch = 19, cex = 2)
plot(x, y, col = color_gradient(y, c("yellow", "blue")), pch = 19, cex = 2)
plot(x, y, col = color_gradient(y, x_range = c(10, 20)), pch = 19, cex = 2)

DavZim/colorTable documentation built on May 28, 2019, 2:31 p.m.