v_bar: Create a Bar Chart

View source: R/layers.R

v_barR Documentation

Create a Bar Chart

Description

Create a Bar Chart

Usage

v_bar(
  vc,
  mapping = NULL,
  data = NULL,
  name = NULL,
  stack = FALSE,
  percent = FALSE,
  direction = c("vertical", "horizontal"),
  ...,
  serie_id = NULL,
  data_id = NULL,
  data_specs = list()
)

Arguments

vc

A chart initialized with vchart().

mapping

Default list of aesthetic mappings to use for chart.

data

Default dataset to use for chart. If not already a data.frame, it will be coerced to with as.data.frame.

name

Name for the serie, only used for single serie (no color/fill aesthetic supplied).

stack

Whether to stack the data or not (if fill aesthetic is provided).

percent

Whether to display the data as a percentage.

direction

The direction configuration of the chart: "vertical" (default) or "horizontal".

...

Additional parameters for the serie.

data_id, serie_id

ID for the data/serie, can be used to further customize the chart with v_specs().

data_specs

Additional options for the data, see online documentation.

Value

A vchart() htmlwidget object.

Examples


library(vchartr)

# Classic Bar Chart
vchart(top_generation) %>% 
  v_bar(aes(country, electricity_generation))

# Horizontal Bar Chart
vchart(top_generation) %>% 
  v_bar(aes(country, electricity_generation), direction = "horizontal")

# Grouped Bar Chart
vchart(subset(world_electricity, type == "total")) %>% 
  v_bar(aes(year, generation, fill = source))

# Horizontal Grouped Bar Chart
vchart(subset(world_electricity, type == "total")) %>% 
  v_bar(aes(year, generation, fill = source), direction = "horizontal")

# Stacked Bar Chart
vchart(subset(world_electricity, type == "total")) %>% 
  v_bar(aes(year, generation, fill = source), stack = TRUE)

# Percentage Stacked Bar Chart
vchart(subset(world_electricity, type == "total")) %>% 
  v_bar(aes(year, generation, fill = source), stack = TRUE, percent = TRUE)


vchartr documentation built on April 12, 2025, 1:51 a.m.