Create a gradient of colors and optionally a colorbar
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)
Integer: How many distinct colors you want. If not odd, converted to n + 1
Defaults to 21
String: Acts as a shortcut to defining lo
, mid
, etc for a number of defaults:
"french", "penn", "grnblkred",
String: Which colorspace to use. Option: "rgb", or "Lab". Default = "rgb".
Recommendation: If mid
is "white" or "black" (default), use "rgb", otherwise "Lab"
Color for low end
Color for low-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.
Color for middle-high
Color for high end
Logical: Plot the colors horizontally
Logical: Create a vertical colorbar
Integer: How many steps you would like in the colorbar
Vector, length 4: Colorbar margins. Default: c(1, 1, 1, 1)
Logical: If TRUE, colorbar will be added to existing plot
Vector: Margins for colorbar (See par("mar")
)
Float: Position of axis (See axis("pos")
)
Integer 0,1,2,3: Style of axis labels. 0: Always parallel to the axis, 1: Horizontal, 2: Perpendicular, 3: Vertical. Default = 1
Float: Adjustment parallel to the reading direction (See par("adj")
)
FLoat: Character expansion factor for colorbar (See par("cex")
)
Numeric: Lowest value in colorbar
Numeric: Middle value in colorbar
Numeric: Max value in colorbar
Float: Chracter expansion for axis
String (Optional: Path to file to save colorbar
Float: Width for PDF output. Default = 3
Float: Height for PDF output. Default = 7
String: "light", "dark"
Color: Background color
Color: Colorbar text color
Logical: Create colorbar using plotly
(instead of base R graphics)
Float: Width for plotly colorbar. Default = 80
Float: Height for plotly colorbar. Default = 500
Logical: If TRUE, return plotly
object
Vector: Plotly margins. Default = c(0, 0, 0, 0)
Float: Padding for plotly
. Default = 0
Logical: If TRUE (Default), reset par
settings after running
Invisible vector of hexadecimal colors / plotly object if rtrn.plotly = TRUE
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% change from the next.
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