Skip to contents

Helper to add a bar image legend to plots

Usage

legend_bar(position, col, width_prop = 0.03, heigh_prop = 0.18,
           title = "Legend", labels = c("Low", "High"), digits = 0,
           labels_offset = 0.2, horizontal = FALSE, alpha = 1, border = NULL,
           cex = NULL, inset = 0.05, insetx = NULL, insety = NULL)

Arguments

position

(numeric or character) position of the bottom left corner of the legend. If numeric, x and y coordinates. If character, options are: "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right", or "center".

col

color palette. A vector of contiguous colors. It can be generated using functions like purplow (e.g., darkros(255)).

width_prop

width of bar legend represented as a proportion of the entire plotting width. Default = 0.03.

heigh_prop

heigh of bar legend represented as a proportion of the entire plotting heigh. Default = 0.18.

title

legend title. Default = "Legend".

labels

(numeric or character) labels for the legend. Default = c("Low", "High").

digits

(numeric) number of decimal places to round numeric labels. Default = 0.

labels_offset

offset of labels from bar. Default = 0.2.

horizontal

(logical) should the legend be horizontal. Default = FALSE.

alpha

(numeric) alpha level 0-1. Default = 1.

border

color for the border of the legend bar. The default, NULL, does not plot a border.

cex

character expansion factor relative to current. Default = NULL.

inset

inset distances from plot margins relative to plot region. Default = 0.05.

insetx

inset from x margins. The default, NULL, uses inset.

insety

inset from y margins. The default, NULL, uses inset.

Value

A bar legend for a plot.