encode: Encode all "channels"

Description Usage Arguments Note References Examples

Description

Vega-Lite has many "encoding channels". Each channel definition object must describe the data field encoded by the channel and its data type, or a constant value directly mapped to the mark properties. In addition, it can describe the mapped field’s transformation and properties for its scale and guide.

Grouping data is another important operation in visualizing data. For aggregated plots, all encoded fields without aggregate functions are used as grouping fields in the aggregation (similar to fields in GROUP BY in SQL). For line and area marks, mapping a data field to color or shape channel will group the lines and stacked areas by the field.

detail channel allows providing an additional grouping field (level) for grouping data in aggregation without mapping data to a specific visual channel.

Create a horizontal ribbon of panels

Create a vertical ribbon of panels

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
encode_vl(vl, chnl = "x", field = NULL, type = "auto", value = NULL,
  aggregate = NULL, sort = NULL, padding = NULL, round = NULL,
  stack = NULL)

encode_x(vl, ...)

encode_y(vl, ...)

encode_color(vl, ...)

encode_shape(vl, ...)

encode_size(vl, ...)

encode_text(vl, ...)

encode_detail(vl, field = NULL, type = "auto", value = NULL, ...)

encode_order(vl, field = NULL, type = "auto", value = NULL, ...)

encode_path(vl, field = NULL, type = "auto", value = NULL, ...)

facet_col(vl, field = NULL, type = "auto", value = NULL, ...)

facet_row(vl, field = NULL, type = "auto", value = NULL, ...)

Arguments

vl

Vega-Lite object created by vegalite

chnl

a channel to encode like x, y, color, shape, size, text, detail, order, path

field

single element character vector naming the column. Can be * is using aggregate.

type

the encoded field’s type of measurement. This can be either a full type name (quantitative, temporal, ordinal, and nominal) or an initial character of the type name (Q, T, O, N). This property is case insensitive. If auto is used, the type will be guessed (so you may want to actually specify it if you want consistency).

value

if field is not specified, a constant value in visual domain.

aggregate

perform aggregation on field. See Supported Aggregation Options for more info on valid operations. Leave NULL for no aggregation.

sort

either one of ascending, descending or (for ordinal scales) the result of a call to sort_def

padding

facet padding

round

round values

stack

how to stack values, in case mark is bar or area. Should be "zero","center","normalize", or "none" or NA.

...

additional arguments to pass to encode_vl

Note

right now, type == "auto" just assume "quantitative". It will eventually get smarter, but you are better off specifying it.

References

Vega-Lite Encoding spec

Vega-Lite Faceting

Vega-Lite Faceting

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
dat <- jsonlite::fromJSON('[
    {"a": "A","b": 28}, {"a": "B","b": 55}, {"a": "C","b": 43},
    {"a": "D","b": 91}, {"a": "E","b": 81}, {"a": "F","b": 53},
    {"a": "G","b": 19}, {"a": "H","b": 87}, {"a": "I","b": 52}
  ]')

vegalite() %>%
  add_data(dat) %>%
  encode_x("a", "ordinal") %>%
  encode_y("b", "quantitative") %>%
  mark_bar()
vegalite() %>%
  view_size(200, 200) %>%
  add_data("https://vega.github.io/vega-editor/app/data/stocks.csv") %>%
  encode_x("date", "temporal") %>%
  encode_y("price", "quantitative") %>%
  encode_detail("symbol", "nominal") %>%
  mark_line()
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") %>%
  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.