ColorBar | R Documentation |
Generates a color bar to use as colouring function for map plots and
optionally draws it (horizontally or vertically) to be added to map
multipanels or plots. It is possible to draw triangles at the ends of the
colour bar to represent values that go beyond the range of interest. A
number of options is provided to adjust the colours and the position and
size of the components. The drawn colour bar spans a whole figure region
and is compatible with figure layouts.
The generated colour bar consists of a set of breaks that define the
length(brks) - 1 intervals to classify each of the values in each of the
grid cells of a two-dimensional field. The corresponding grid cell of a
given value of the field will be coloured in function of the interval it
belongs to.
The only mandatory parameters are 'var_limits' or 'brks' (in its second
format, see below).
ColorBar(
brks = NULL,
cols = NULL,
vertical = TRUE,
subsampleg = NULL,
bar_limits = NULL,
var_limits = NULL,
triangle_ends = NULL,
col_inf = NULL,
col_sup = NULL,
color_fun = clim.palette(),
plot = TRUE,
draw_ticks = TRUE,
draw_separators = FALSE,
triangle_ends_scale = 1,
extra_labels = NULL,
title = NULL,
title_scale = 1,
label_scale = 1,
tick_scale = 1,
extra_margin = rep(0, 4),
label_digits = 4,
...
)
brks |
Can be provided in two formats:
This parameter is optional if 'var_limits' is specified. If 'brks' not specified but 'cols' is specified, it will take as value length(cols) + 1. If 'cols' is not specified either, 'brks' will take 21 as value. |
cols |
Vector of length(brks) - 1 valid colour identifiers, for each
interval defined by the breaks. This parameter is optional and will be
filled in with a vector of length(brks) - 1 colours generated with the
function provided in 'color_fun' ( |
vertical |
TRUE/FALSE for vertical/horizontal colour bar (disregarded if plot = FALSE). |
subsampleg |
The first of each subsampleg breaks will be ticked on the colorbar. Takes by default an approximation of a value that yields a readable tick arrangement (extreme breaks always ticked). If set to 0 or lower, no labels are drawn. See the code of the function for details or use 'extra_labels' for customized tick arrangements. |
bar_limits |
Vector of two numeric values with the extremes of the range of values represented in the colour bar. If 'var_limits' go beyond this interval, the drawing of triangle extremes is triggered at the corresponding sides, painted in 'col_inf' and 'col_sup'. Either of them can be set as NA and will then take as value the corresponding extreme in 'var_limits' (hence a triangle end won't be triggered for these sides). Takes as default the extremes of 'brks' if available, else the same values as 'var_limits'. |
var_limits |
Vector of two numeric values with the minimum and maximum values of the field to represent. These are used to know whether to draw triangle ends at the extremes of the colour bar and what colour to fill them in with. If not specified, take the same value as the extremes of 'brks'. Hence the parameter 'brks' is mandatory if 'var_limits' is not specified. |
triangle_ends |
Vector of two logical elements, indicating whether to force the drawing of triangle ends at each of the extremes of the colour bar. This choice is automatically made from the provided 'brks', 'bar_limits', 'var_limits', 'col_inf' and 'col_sup', but the behaviour can be manually forced to draw or not to draw the triangle ends with this parameter. If 'cols' is provided, 'col_inf' and 'col_sup' will take priority over 'triangle_ends' when deciding whether to draw the triangle ends or not. |
col_inf |
Colour to fill the inferior triangle end with. Useful if specifying colours manually with parameter 'cols', to specify the colour and to trigger the drawing of the lower extreme triangle, or if 'cols' is not specified, to replace the colour automatically generated by ColorBar(). |
col_sup |
Colour to fill the superior triangle end with. Useful if specifying colours manually with parameter 'cols', to specify the colour and to trigger the drawing of the upper extreme triangle, or if 'cols' is not specified, to replace the colour automatically generated by ColorBar(). |
color_fun |
Function to generate the colours of the color bar. Must take an integer and must return as many colours. The returned colour vector can have the attribute 'na_color', with a colour to draw NA values. This parameter is set by default to clim.palette(). |
plot |
Logical value indicating whether to only compute its breaks and colours (FALSE) or to also draw it on the current device (TRUE). |
draw_ticks |
Whether to draw ticks for the labels along the colour bar (TRUE) or not (FALSE). TRUE by default. Disregarded if 'plot = FALSE'. |
draw_separators |
Whether to draw black lines in the borders of each of the colour rectancles of the colour bar (TRUE) or not (FALSE). FALSE by default. Disregarded if 'plot = FALSE'. |
triangle_ends_scale |
Scale factor for the drawn triangle ends of the colour bar, if drawn at all. Takes 1 by default (rectangle triangle proportional to the thickness of the colour bar). Disregarded if 'plot = FALSE'. |
extra_labels |
Numeric vector of extra labels to draw along axis of the colour bar. The number of provided decimals will be conserved. Disregarded if 'plot = FALSE'. |
title |
Title to draw on top of the colour bar, most commonly with the units of the represented field in the neighbour figures. Empty by default. |
title_scale |
Scale factor for the 'title' of the colour bar. Takes 1 by default. |
label_scale |
Scale factor for the labels of the colour bar. Takes 1 by default. |
tick_scale |
Scale factor for the length of the ticks of the labels along the colour bar. Takes 1 by default. |
extra_margin |
Extra margins to be added around the colour bar, in the format c(y1, x1, y2, x2). The units are margin lines. Takes rep(0, 4) by default. |
label_digits |
Number of significant digits to be displayed in the labels of the colour bar, usually to avoid too many decimal digits overflowing the figure region. This does not have effect over the labels provided in 'extra_labels'. Takes 4 by default. |
... |
Arguments to be passed to the method. Only accepts the following
graphical parameters: |
brks |
Breaks used for splitting the range in intervals. |
cols |
Colours generated for each of the length(brks) - 1 intervals. Always of length length(brks) - 1. |
col_inf |
Colour used to draw the lower triangle end in the colour bar (NULL if not drawn at all). |
col_sup |
Colour used to draw the upper triangle end in the colour bar (NULL if not drawn at all). |
cols <- c("dodgerblue4", "dodgerblue1", "forestgreen", "yellowgreen", "white",
"white", "yellow", "orange", "red", "saddlebrown")
lims <- seq(-1, 1, 0.2)
ColorBar(lims, cols)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.