Skip to contents

Draws a bar chart, the largest bar first: the name over each bar, cut short when it is too long, and the value at its tip.

Usage

bars_svg(data, x, w, col, unit, fmt = NULL)

Arguments

data

A data frame of label and value, the largest first.

x, w

Where the chart starts, and its width, in pixels.

col

The colours of the card, from card_colors().

unit

The unit of the values, for one and for several, for the tooltips.

fmt

A function that writes the values, such as fmt_bytes(), or NULL for counts.

Value

SVG code, a character string.

Examples

data <- data.frame(label = c("rwf", "snp", "rghcard"), value = c(120, 45, 9))
svg <- rghcard:::bars_svg(data, 24, 260, rghcard:::card_colors("light"), c("star", "stars"))
cat(substr(svg, 1, 300))
#> <text x="24.0" y="238.0" font-size="12" font-weight="400" fill="#1f2328" text-anchor="start">rwf</text>
#> <path d="M24.00,245.00 H252.20 A4.00,4.00 0 0 1 256.20,249.00 V251.00 A4.00,4.00 0 0 1 252.20,255.00 H24.00 Z" fill="#257de0"><title>rwf: 120 stars</title></path>
#> <text x="262.2" y="254.0" font-si