Published
Edited
Jun 5, 2020
Insert cell
md`# Citing more who is it`
Insert cell
vegalite({
$schema: "https://vega.github.io/schema/vega-lite/v2.0.json",
height: 533,
width: 300,
data: { url: "https://vega.github.io/vega-datasets/data/barley.json" },
description: "Slope graph à la Edward Tufte",
transform: [
{
aggregate: [{ op: "sum", field: "yield", as: "yield" }],
groupby: ["year", "site"]
},
{ as: "first_year", calculate: "min(datum.year, 1931)" },
{ as: "last_year", calculate: "max(datum.year, 1932)" }
],
layer: [
{
mark: "line",
description: "lines linking the `yield` values",
encoding: {
x: {
field: "year",
type: "ordinal",
axis: {
orient: "top",
zindex: 0,
title: "",
grid: true,
domain: false,
ticks: false,
labels: true,
labelAngle: 0
}
},
y: {
field: "yield",
type: "quantitative",
axis: null,
scale: { zero: false }
},
detail: { field: "site", type: "nominal" },
color: { value: "lightgray" },
size: { value: 1.5 }
}
},
{
mark: "circle",
description: "white circles to contain the `yield` values",
encoding: {
x: {
field: "year",
type: "ordinal",
axis: {
orient: "top",
zindex: 0,
title: "",
grid: true,
domain: false,
ticks: false,
labels: true
}
},
y: { field: "yield", type: "quantitative", axis: null },
size: { value: 400 },
color: { value: "white" },
opacity: { value: 1 }
}
},
{
mark: "text",
description: "`yield` values",
encoding: {
x: {
field: "year",
type: "ordinal",
axis: {
orient: "top",
zindex: 0,
title: "",
grid: true,
domain: false,
ticks: false,
labels: true
}
},
y: { field: "yield", type: "quantitative", axis: null },
detail: { field: "site", type: "nominal" },
text: { field: "yield", type: "quantitative" },
color: { value: "black" },
size: { value: 10 }
}
},
{
mark: { type: "text", style: "last_name" },
transform: [{ filter: "datum.year === datum.last_year" }],
description: "last year site label",
encoding: {
x: {
field: "year",
type: "ordinal",
axis: {
orient: "top",
zindex: 0,
title: "",
grid: true,
domain: false,
ticks: false,
labels: true
}
},
y: { field: "yield", type: "quantitative", axis: null },
text: { field: "site", type: "nominal" },
size: { value: 10 },
color: { value: "black" }
}
},
{
mark: { type: "text", style: "first_name" },
transform: [{ filter: "datum.year === datum.first_year" }],
description: "first year site label",
encoding: {
x: {
field: "year",
type: "ordinal",
axis: {
orient: "top",
zindex: 0,
title: "",
grid: true,
domain: false,
ticks: false,
labels: true
}
},
y: { field: "yield", type: "quantitative", axis: null },
text: { field: "site", type: "nominal" },
size: { value: 10 },
color: { value: "black" }
}
}
],
config: {
view: { strokeWidth: 0 },
numberFormat: ".0f",
axis: {
gridWidth: 0,
labelColor: "black",
labelFontSize: 11,
labelAngle: 0
},
text: { align: "center", baseline: "middle" },
style: {
last_name: { dx: 15, align: "left", baseline: "middle" },
first_name: { dx: -15, align: "right", baseline: "middle" }
}
}
})
Insert cell
md`## Appendix`
Insert cell
// Create an embed function that applies the loader and theme
vegalite = function(spec) {
return vegaEmbed(spec, {loader: vegaEmbed.vega.loader({baseURL: 'https://vega.github.io/vega/'}), theme: "quartz", actions: true})
}
Insert cell
vegaEmbed = require("vega-embed@6")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more