forked from procyon-rs/vega_lite_4.rs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cloropleth_unemployment.rs
49 lines (45 loc) · 1.67 KB
/
cloropleth_unemployment.rs
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use vega_lite_5::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// the chart
let chart = VegaliteBuilder::default()
.title("Choropleth of Unemployment Rate per County")
.data(
UrlDataBuilder::default()
.url("https://raw.githubusercontent.com/vega/vega-datasets/master/data/us-10m.json")
.format(
DataFormatBuilder::default()
.data_format_type(DataFormatType::Topojson)
.feature("counties")
.build()?,
)
.build()?,
)
.mark(Mark::Geoshape)
.transform(vec![TransformBuilder::default()
.lookup("id")
.from(LookupBuilder::default()
.data(DataBuilder::default()
.url("https://raw.githubusercontent.com/vega/vega-datasets/master/data/unemployment.tsv")
.build()?)
.key("id")
.fields(vec!["rate".to_string()])
.build()?)
.build()?])
.projection(ProjectionBuilder::default().projection_type(ProjectionType::AlbersUsa).build()?)
.encoding(
EdEncodingBuilder::default()
.color(
ColorClassBuilder::default()
.field("rate")
.mark_prop_def_gradient_string_null_type(Type::Quantitative)
.build()?,
)
.build()?,
)
.build()?;
// display the chart using `showata`
chart.show()?;
// print the vega lite spec
eprint!("{}", chart.to_string()?);
Ok(())
}