Published unlisted
Edited
Apr 16, 2022
1 fork
Insert cell
import {vl} from '@vega/vega-lite-api-v5'
Insert cell
df2 = data['movies.json']() // get hold of movies dataset
Insert cell
data = require('vega-datasets@1') // import vega_datasets
Insert cell
df2[0]['IMDB_Rating']
Insert cell
plot = vl.markBar().data(df2).encode(
vl.x().fieldQ('IMDB_Rating').bin(true),
vl.y().count()
)
Insert cell
plot.render()
Insert cell
vl.markBar().data(df2).encode(
vl.x().fieldQ('IMDB_Rating').bin(false),
vl.y().count()
).render()
Insert cell
{
const plot = vl.markCircle().encode({
x: {field: 'precip', type: 'quantitative', aggregate: 'average'},
y: {field: 'city', type: 'nominal'}
});
return html`<pre>${JSON.stringify(plot.toObject(), 0, 2)}</pre>`; // format JSON data
}
Insert cell
vl.markBar().data(df2).render()
Insert cell
Insert cell
// html`<pre>${JSON.stringify(plot.toObject(), 0, 2)}</pre>`;
Insert cell
Insert cell
vegalite = require("@observablehq/vega-lite@0.2")
Insert cell
vegalite.compile(plot.toObject()).spec;
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