Skip to contents

Quick bar chart from x/y data.

Usage

draw_bar(
  x,
  y = NULL,
  palette = NULL,
  stack = FALSE,
  horizontal = FALSE,
  xlab = NULL,
  ylab = NULL,
  title = NULL,
  theme = NULL,
  margins = DEFAULT_MARGINS,
  width = NULL,
  height = NULL,
  element_id = NULL,
  filename = NULL,
  bar_width = NULL,
  order = "input",
  legend_position = "top",
  legend_placement = "outside"
)

Arguments

x

Character or Numeric: Category labels, or values when y is omitted. A matrix or two-dimensional table supplies categories in rows and series in columns. A one-dimensional table supplies counts and category names.

y

Numeric or named list: Bar heights.

palette

Optional Character: Bar color or colors. For multiple series, colors are applied per series and recycled as needed. For a single series, a single color styles the whole series; multiple colors are recycled across individual bars. palette takes precedence over the theme palette.

stack

Logical: Whether to stack bars.

horizontal

Logical: Whether to draw horizontal bars.

xlab

Optional Character: X-axis title (bottom axis).

ylab

Optional Character: Y-axis title (left axis).

title

Optional Character: Chart title.

theme

Optional Theme: Theme override. The palette inside the theme can be overridden per-chart with the palette argument.

margins

Optional Named numeric vector or named list: Plot margins in pixels (or percentage strings) for any of "top", "right", "bottom", "left". Unspecified sides keep echarts' default auto-sizing. See draw_line() for details.

width

Optional Character or Numeric: Widget width.

height

Optional Character or Numeric: Widget height.

element_id

Optional Character: Explicit DOM element ID for the widget container. NULL lets htmlwidgets generate one.

filename

Optional Character: If provided, save the widget to this file via save_drawing().

bar_width

Optional Numeric (0, Inf): Bar thickness in pixels. NULL lets ECharts size bars from the category spacing.

order

Character {"input", "increasing", "decreasing"}: Order categories by their total across series, retaining ties and placing missing totals last.

legend_position

Character {"top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right"}: Legend anchor. Top/bottom anchors use horizontal rows; left/right anchors use a vertical column. Corner anchors align within the top or bottom row.

legend_placement

Character {"outside", "inside"}: Relation to the plotting area. Outside placement reserves space for the complete legend; inside placement overlays the data. Neither setting adds a missing legend.

Value

htmlwidget: Widget object.

Examples

draw_bar(x = c("A", "B", "C"), y = c(3, 7, 2), title = "Counts")