Learn R Programming

vchartr (version 0.1.4)

v_facet_wrap: Facets for vchart

Description

Create matrix of charts by row and column faceting variable (v_facet_grid), or by specified number of row and column for faceting variable(s) (v_facet_wrap).

Usage

v_facet_wrap(
  vc,
  facets,
  nrow = NULL,
  ncol = NULL,
  scales = c("fixed", "free", "free_y", "free_x"),
  labeller = label_value
)

Value

A vchart()

htmlwidget object.

Arguments

vc

A chart initialized with vchart().

facets

Variable(s) to use for facetting, wrapped in vars(...).

nrow, ncol

Number of row and column in output matrix.

scales

Should scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y")?

labeller

A function with one argument containing for each facet the value of the faceting variable.

Examples

Run this code
library(vchartr)
library(ggplot2)

# Use vars() to supply faceting variables:
vchart(mpg) %>% 
  v_scatter(aes(displ, hwy)) %>% 
  v_facet_wrap(vars(class))

# Control the number of rows and columns with nrow and ncol
vchart(mpg) %>% 
  v_scatter(aes(displ, hwy)) %>% 
  v_facet_wrap(vars(class), ncol = 3)

# You can facet by multiple variables
vchart(mpg) %>% 
  v_scatter(aes(displ, hwy)) %>% 
  v_facet_wrap(vars(cyl, drv))

# Use the `labeller` option to control how labels are printed:
vchart(mpg) %>% 
  v_scatter(aes(displ, hwy)) %>% 
  v_facet_wrap(vars(cyl, drv), labeller = label_both)

# To change the order in which the panels appear, change the levels
# of the underlying factor.
mpg$class2 <- reorder(mpg$class, mpg$displ)
vchart(mpg) %>% 
  v_scatter(aes(displ, hwy)) %>% 
  v_facet_wrap(vars(class2), ncol = 3)

# By default, the same scales are used for all panels. You can allow
# scales to vary across the panels with the `scales` argument.
vchart(mpg) %>% 
  v_scatter(aes(displ, hwy)) %>% 
  v_facet_wrap(vars(class), scales = "free")

Run the code above in your browser using DataLab