colorGrad: Color Gradient

View source: R/colorGrad.R

colorGradR Documentation

Color Gradient

Description

Create a gradient of colors and optionally a colorbar

Usage

colorGrad(
  n = 21,
  colors = NULL,
  space = c("rgb", "Lab"),
  lo = "#18A3AC",
  lomid = NULL,
  mid = NULL,
  midhi = NULL,
  hi = "#F48024",
  preview = FALSE,
  colorbar = FALSE,
  cb.n = 21,
  cb.mar = c(1, 1, 1, 1),
  cb.add = FALSE,
  cb.add.mar = c(5, 0, 2, 5),
  cb.axis.pos = 1.1,
  cb.axis.las = 1,
  cb.axis.hadj = 0,
  cb.cex = 6,
  bar.min = -1,
  bar.mid = 0,
  bar.max = 1,
  cex = 1.2,
  filename = NULL,
  pdf.width = 3,
  pdf.height = 7,
  theme = getOption("rt.theme", "light"),
  bg = NULL,
  col.text = NULL,
  plotlycb = FALSE,
  plotly.width = 80,
  plotly.height = 500,
  rtrn.plotly = FALSE,
  margins = c(0, 0, 0, 0),
  pad = 0,
  par.reset = TRUE
)

Arguments

n

Integer: How many distinct colors you want. If not odd, converted to n + 1 Defaults to 21

colors

Character: Acts as a shortcut to defining lo, mid, etc for a number of defaults: "french", "penn", "grnblkred",

space

Character: Which colorspace to use. Option: "rgb", or "Lab". Default = "rgb". Recommendation: If mid is "white" or "black" (default), use "rgb", otherwise "Lab"

lo

Color for low end

lomid

Color for low-mid

mid

Color for middle of the range or "mean", which will result in colorOp(c(lo, hi), "mean"). If mid = NA, then only lo and hi are used to create the color gradient.

midhi

Color for middle-high

hi

Color for high end

preview

Logical: Plot the colors horizontally

colorbar

Logical: Create a vertical colorbar

cb.n

Integer: How many steps you would like in the colorbar

cb.mar

Vector, length 4: Colorbar margins. Default: c(1, 1, 1, 1)

cb.add

Logical: If TRUE, colorbar will be added to existing plot

cb.add.mar

Vector: Margins for colorbar (See par("mar"))

cb.axis.pos

Float: Position of axis (See axis("pos"))

cb.axis.las

Integer 0,1,2,3: Style of axis labels. 0: Always parallel to the axis, 1: Horizontal, 2: Perpendicular, 3: Vertical. Default = 1

cb.axis.hadj

Float: Adjustment parallel to the reading direction (See par("adj"))

cb.cex

FLoat: Character expansion factor for colorbar (See par("cex"))

bar.min

Numeric: Lowest value in colorbar

bar.mid

Numeric: Middle value in colorbar

bar.max

Numeric: Max value in colorbar

cex

Float: Character expansion for axis

filename

String (Optional: Path to file to save colorbar

pdf.width

Float: Width for PDF output. Default = 3

pdf.height

Float: Height for PDF output. Default = 7

theme

Character: "light", "dark"

bg

Color: Background color

col.text

Color: Colorbar text color

plotlycb

Logical: Create colorbar using plotly (instead of base R graphics)

plotly.width

Float: Width for plotly colorbar. Default = 80

plotly.height

Float: Height for plotly colorbar. Default = 500

rtrn.plotly

Logical: If TRUE, return plotly object

margins

Vector: Plotly margins. Default = c(0, 0, 0, 0)

pad

Float: Padding for plotly. Default = 0

par.reset

Logical: If TRUE (Default), reset par settings after running

Details

It is best to provide an odd number, so that there is always an equal number of colors on either side of the midpoint. For example, if you want a gradient from -1 to 1 or equivalent, an n = 11, will give 5 colors on either side of 0, each representing a 20\

colors can be defined as a sequence of 3-letter color abbreviations of 2, 3, 4, or 5 colors which will correspond to values: {"lo","hi"}; {"lo", "mid", "hi"}; {"lo", "mid", "midhi", "hi"}, and {"lo", "lomid", "mid", "midhi", "hi"}, respectively. For example, try colorGrad(21, "blugrnblkredyel", colorbar = TRUE) 3-letter color abbreviations: wht: white; blk: black; red; grn: green; blu: blue; yel: yellow; rng: orange; prl: purple

Value

Invisible vector of hexadecimal colors / plotly object if rtrn.plotly = TRUE

Author(s)

E.D. Gennatas


egenn/rtemis documentation built on Dec. 17, 2024, 6:16 p.m.