sort_def {vegalite} | R Documentation |
You can sort by aggregated value of another “sort” field by creating a
sort field definition object. All three properties must be non-NULL
.
sort_def(field, op = NULL, order = c("ascending", "descending"))
field |
the field name to aggregate over. |
op |
a valid aggregation operator. |
order |
either |
vegalite() %>%
add_data("https://vega.github.io/vega-editor/app/data/cars.json") %>%
encode_x("Horsepower", type="quantitative", aggregate="mean") %>%
encode_y("Origin", "ordinal", sort=sort_def("Horsepower", "mean")) %>%
mark_bar()