Published
Edited
Sep 23, 2022
1 fork
1 star
Insert cell
# 可视化2022秋
Insert cell
Insert cell
embed = require('vega-embed@6')
Insert cell
d3 = require("d3-dsv@1")
Insert cell
df = d3.csvParse(await FileAttachment('census2000.csv').text())
Insert cell
Insert cell
Insert cell
Insert cell
embed(
{
"data": {"values":data_trans(df)},
"transform": [
{"filter": "datum.Year == 2000"},
{"calculate": "datum.Sex == 2 ? 'Female' : 'Male'", "as": "gender"},
{"calculate": "datum.Sex == 2 ? -datum.People : datum.People", "as": "signed_people"}
],
"width": 300,
"height": 200,
"mark": "bar",
"encoding": {
"y": {
"field": "Age",
"type": "ordinal",
"sort": "descending"
},
"x": {
"aggregate": "sum", "field": "signed_people",
"title": "Population",
"axis": {"format": "s"}
},
"color": {
"field": "gender",
"scale": {"range": ["#675193", "#ca8861"]},
"legend": {"orient": "top", "title": null}
}
},
"config": {
"view": {"stroke": null},
"axis": {"grid": true}
}
}
)
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more