calculate: Derive new fields

Description Usage Arguments Examples

Description

Derive new fields

Usage

1
calculate(vl, field, expr)

Arguments

vl

Vega-Lite object created by vegalite

field

the field name in which to store the computed value.

expr

a string containing an expression for the formula. Use the variable "datum" to refer to the current data object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
vegalite() %>%
  add_data("https://vega.github.io/vega-editor/app/data/population.json") %>%
  add_filter("datum.year == 2000") %>%
  calculate("gender", 'datum.sex == 2 ? "Female" : "Male"') %>%
  encode_x("gender", "nominal") %>%
  encode_y("people", "quantitative", aggregate="sum") %>%
  encode_color("gender", "nominal") %>%
  scale_x_ordinal_vl(range_step=8) %>%
  scale_color_nominal_vl(range=c("#EA98D2", "#659CCA")) %>%
  facet_col("age", "ordinal", padding=4) %>%
  axis_x(remove=TRUE) %>%
  axis_y(title="population", grid=FALSE) %>%
  view_config(stroke_width=0) %>%
  mark_bar()

hrbrmstr/vegalite documentation built on May 17, 2019, 5:38 p.m.