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,
return_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". 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
color_op(c(lo, hi), "mean")
. Ifmid = NA
, then onlylo
andhi
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.
- 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.
- pdf_height
Float: Height for PDF output.
- 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.
- plotly_height
Float: Height for plotly colorbar.
- return_plotly
Logical: If TRUE, return
plotly
object- margins
Vector: Plotly margins.
- pad
Float: Padding for
plotly
.- 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