Skip to contents

Axis scale for continuous data

Usage

v_scale_x_continuous(
  vc,
  name = NULL,
  breaks = NULL,
  pretty = TRUE,
  labels = NULL,
  labels_tooltip = labels,
  zero = NULL,
  min = NULL,
  max = NULL,
  ...,
  position = "bottom"
)

v_scale_y_continuous(
  vc,
  name = NULL,
  breaks = NULL,
  pretty = TRUE,
  labels = NULL,
  labels_tooltip = labels,
  zero = NULL,
  min = NULL,
  max = NULL,
  ...,
  position = "left"
)

v_scale_x_log(
  vc,
  name = NULL,
  breaks = NULL,
  pretty = TRUE,
  labels = NULL,
  labels_tooltip = labels,
  zero = NULL,
  min = NULL,
  max = NULL,
  ...,
  position = "bottom"
)

v_scale_y_log(
  vc,
  name = NULL,
  breaks = NULL,
  pretty = TRUE,
  labels = NULL,
  labels_tooltip = labels,
  zero = NULL,
  min = NULL,
  max = NULL,
  ...,
  position = "left"
)

Arguments

vc

An htmlwidget created with vchart() or specific chart's type function.

name

Title for the axis.

breaks

One of:

  • A single numeric value giving the number of breaks.

  • A numeric vector of positions.

pretty

Use pretty() to dertimen breaks if breaks is a single numeric value.

labels, labels_tooltip

The format to be applied on numeric in the labels/tooltip. Either:

  • A single character indicating the D3 format.

  • A JS function, such as format_num_d3().

zero

Force axis to start at 0.

min

Minimum value on the axis.

max

Maximum value on the axis.

...

Additional parameters for the axis.

position

Position of the axis.

Value

A vchart() htmlwidget object.

Examples


library(vchartr)

# Add a title to the axis
vchart(top_generation) %>%
  v_bar(aes(country, electricity_generation)) %>%
  v_scale_y_continuous(name = "Electricity generation")
vchart(subset(world_electricity, type == "total")) %>% v_bar(aes(year, generation, fill = source)) %>% v_scale_y_continuous(name = "Electricity generation")
# Specify number of breaks vchart(top_generation) %>% v_bar(aes(country, electricity_generation)) %>% v_scale_y_continuous(breaks = 10)
# Specify breaks position vchart(top_generation) %>% v_bar(aes(country, electricity_generation)) %>% v_scale_y_continuous(breaks = c(0, 5000, 10000))
# Format labels vchart(top_generation) %>% v_bar(aes(country, electricity_generation)) %>% v_scale_y_continuous(labels = "~s")
# Format labels with options vchart(top_generation) %>% v_bar(aes(country, electricity_generation)) %>% v_scale_y_continuous(labels = format_num_d3(",", suffix = " TWh", locale = "fr-FR"))
vchart(subset(world_electricity, type == "total")) %>% v_bar(aes(year, generation, fill = source)) %>% v_scale_y_continuous(labels = format_num_d3(",", suffix = " TWh", locale = "fr-FR"))