Learn R Programming

Kmisc (version 0.5.0)

gradient: Generate Gradient from Continuous Variable

Description

Assign colors based on a continuous variable. Useful for plotting functions where you would like to generate a gradient based on (a function of) the continuous variables you are plotting quickly.

Usage

gradient(x, m = 10, cols = c("darkorange", "grey60", "darkblue"))

Arguments

x
a continuous variable to generate colors over.
m
the number of distinct colors you wish to pull from the pallete.
cols
the colors to interpolate over. passed to colorRampPalette.

See Also

colorRampPalette

Examples

Run this code
dat <- data.frame(y=rnorm(100), x=rnorm(100))
with( dat, plot( y ~ x, col=gradient(y) ) )

Run the code above in your browser using DataLab