twostep_gradient: Create two-step linear gradient

twostep_gradientR Documentation

Create two-step linear gradient

Description

Create two-step linear gradient by gradually blending two linear color gradients

Usage

twostep_gradient(
  color1 = NULL,
  color2 = NULL,
  n = 11,
  lite = TRUE,
  defaultBaseColor = NULL,
  adjust = 1.5,
  do_fixYellow = TRUE,
  debug = FALSE,
  ...
)

Arguments

color1

character color or name of a recognized color gradient.

color2

character color or name of a recognized color gradient; or when color2=NULL then the hue of color1 is shifted to emulate the effect of having a similar neighboring color hue. In this case the input color1 is used as color2 to become the primary output color.

n

integer number of gradient colors to return. When n=0 or n=NULL the output is a color function.

lite

logical indicating whether the background color should be white, or when lite=FALSE the background color is black.

defaultBaseColor

character used to define a specific background color, and therefore overrides lite.

adjust

numeric value used to adjust the relative weight between color1 and color2, where values higher than 1 favor color2 and negative values, or values less than 1 favor color1.

do_fixYellow

logical indicating whether to call jamba::fixYellow() which fixes the greenish hue that sometimes results from what is intended to be pure yellow.

debug

logical indicating whether to create a plot to show the color blending steps.

...

additional arguments are passed to jamba::getColorRamp().

Details

This function is intended to produce a two-step linear gradient effect, similar to the strategy used by RColorBrewer, but without specific color constraints. See examples.

This function takes two color gradients and blends them using a weighting scheme that begins with 100% color1, and gradually becomes 100% color2.

The input color1 and color2 can be any input recognized by jamba::getColorRamp(). For example a single color can be used to create a gradient, or the name of a known color gradient can be used, for example "Reds" will refer to RColorBrewer palette "Reds". See the examples.

In general most gradients can be blended using this function to produce a new color gradient where both the visual intensity and color hue vary along the gradient, making each color step more visibly distinct than when only the visual intensity changes.

When supplying a single color as input to color1 or color2 it sometimes works best to alter the brightness of one or both colors so the intermediate gradients have similar intensities. Experimenting with debug=TRUE is recommended.

See Also

Other colorjam gradients: col_div_xf(), col_linear_xf(), make_jam_divergent()

Examples

ts <- twostep_gradient("yellow", debug=TRUE)

ts1 <- twostep_gradient("orange2", "firebrick", n=11, debug=TRUE)
ts2 <- twostep_gradient("aquamarine", "dodgerblue", n=11, debug=TRUE)

# stitch them together with make_jam_divergent()
ts1ts2 <- make_jam_divergent(list(ts2=ts2), list(ts1=ts1), n=21)
jamba::showColors(ts1ts2)
ts1ts2flat <- make_jam_divergent("dodgerblue", "firebrick", n=21)
jamba::showColors(list(
   twostep=ts1ts2[[1]],
   flat=ts1ts2flat[[1]]))

ts3 <- twostep_gradient("Greens", "Blues", n=11, debug=TRUE)

ts4 <- twostep_gradient("slateblue2", "firebrick", n=11, debug=TRUE)

ts5 <- twostep_gradient("cividis", "inferno", n=11, debug=TRUE, adjust=-1.2)

gr1 <- twostep_gradient("slateblue", "purple", debug=TRUE)
gr2 <- twostep_gradient("gold", "darkorange", debug=TRUE)
div12 <- make_jam_divergent(list(gr1=gr1), list(gr2=gr2))
jamba::showColors(div12)
div12flat <- make_jam_divergent("purple", "gold")
jamba::showColors(list(
   twostep=div12[[1]],
   flat=div12flat[[1]]))

gr1d <- twostep_gradient("slateblue1", "purple", debug=TRUE, lite=FALSE)
gr2d <- twostep_gradient("darkorange", "gold", debug=TRUE, lite=FALSE)
div12d <- make_jam_divergent(list(gr1d=gr1d), list(gr2d=gr2d))
jamba::showColors(div12d)
div12dflat <- make_jam_divergent("purple", "gold", lite=FALSE)
jamba::showColors(list(
   twostep=div12d[[1]],
   flat=div12dflat[[1]]))


jmw86069/colorjam documentation built on March 18, 2024, 3:32 a.m.