| colorbar_horizontal | R Documentation |
Creates a horizontal colorbar as a 4-channel RGBA array. The color
strip and optional tick labels are rendered to PNG using base R
graphics (headless-safe). Returns a 3D array suitable for
image_to_array() or direct composition.
colorbar_horizontal(
colormap,
n_colors = 256L,
width = 600L,
height = 80L,
ticks = NULL,
tick_labels = NULL,
data_range = c(0, 1),
label_cex = 1,
title = NULL,
background = c(1, 1, 1, 1)
)
colormap |
A vector of colors or a function returning colors
(e.g. |
n_colors |
Number of discrete color segments in the gradient. |
width |
Output width in pixels. |
height |
Output height in pixels. |
ticks |
Numeric vector of tick positions in data units
(matching |
tick_labels |
Character vector of tick labels. If |
data_range |
The data range that |
label_cex |
Label size multiplier. |
title |
Optional title string drawn above the color strip (horizontal) or to the right (vertical). |
background |
Background RGBA color (0-1 scale). |
A 3D array of dimensions (height, width, 4) with values in
[0, 1].
cbar <- colorbar_horizontal(viridis_colormap, data_range = c(-2, 3),
title = "Value")
dim(cbar) # height x width x 4
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.