Public
Edited
May 27, 2022
12 forks
Importers
128 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
alphabet = FileAttachment("alphabet.csv").csv() // about file attachments https://observablehq.com/@observablehq/file-attachments
Insert cell
alphabet[0] // what a row of data in `alphabet` looks like
Insert cell
// about viewof https://observablehq.com/@observablehq/a-brief-introduction-to-viewof
viewof simpleBar = vl.markBar() // Make a bar chart
.data(alphabet) // Using the alphabet data
.encode(
vl.x().fieldO("letter"), // .sort(vl.fieldQ("frequency").order("descending")), // Letters are ordinal on the x-axis
vl.y().fieldQ("frequency").axis({ format: "%" }) // Frequency on the y-axis, formatted as percent
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
viewof horizontalBar = vl.markBar()
.data(alphabet)
.encode(
vl.y().fieldO("letter"),
vl.x().fieldQ("frequency").axis({ format: "%" })
)
.render()
Insert cell
Insert cell
vowels = alphabet.map(d => ({...d, vowel: "AEIOU".includes(d.letter)}))
Insert cell
viewof aggregatedBar = vl.markBar()
.data(vowels)
.encode(
vl.x().sum("frequency").axis({ format: "%" }),
vl.y().fieldN("vowel")
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
weather = FileAttachment("pwm-weather@1.csv").csv()
Insert cell
Insert cell
weather[0] // A sample of the weather data
Insert cell
Insert cell
viewof stackedBar = vl.markBar()
.data(weather)
.encode(
vl.x().fieldO("date").timeUnit("utcmonth"),
vl.y().count(), // .stack("normalize").axis({ format: "%" }),
vl.color().fieldN("condition") // .scale({ range: weatherColors })
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
weatherColors = ["darkgray", "steelblue", "paleturquoise", "gold"]
Insert cell
Insert cell
viewof groupedBar = vl.markBar()
.data(weather)
.encode(
vl.column().fieldO("date").timeUnit("utcmonth"),
vl.x().fieldN("condition").axis({ title: null }),
vl.y().count(),
vl.color().fieldN("condition").scale({ range: weatherColors })
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
marketCap = FileAttachment("market-cap.csv").csv()
Insert cell
marketCap[0]
Insert cell
viewof line = vl.markLine()
//.data(marketCap)
.data(marketCap.filter(d => new Date(d.date) > new Date(2018, 0, 1)))
.encode(
vl.x().fieldT("date"), // date parsing!
vl.y().fieldQ("market cap").axis({ format: "$s" }),
vl.color().fieldN("symbol") // .sort(vl.max("market cap").order("descending"))
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof area = vl.markArea()
.data(marketCap)
.encode(
vl.x().fieldT("date").timeUnit("yearmonth"),
vl.y().mean("market cap").axis({ format: "$s" }),
vl.color().fieldN("symbol")
)
.render()
Insert cell
Insert cell
viewof scatter = vl.markPoint()
.data(weather)
.encode(
vl.x().fieldT("date"), // .timeUnit('utcmonthdate'),
vl.y().fieldQ("tmax"),
vl.color().fieldN("condition").scale({ range: weatherColors }),
// vl.shape().fieldN("condition")
)
.render()
Insert cell
Insert cell
Insert cell
viewof strip = vl.markTick()
.data(weather)
.encode(
vl.x().fieldT("date").timeUnit('utcmonthdate'),
vl.y().fieldO("date").timeUnit("utcyear"),
// vl.y().fieldN("condition"),
vl.color().fieldN("condition").scale({ range: weatherColors }),
// vl.size().fieldQ("tmax")
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
viewof heatmap = vl.markRect({tooltip: {"content": "data"}, clip: true})
.data(weather)
.encode(
vl.y().fieldO("date").timeUnit("month"),
vl.x().fieldO("date").timeUnit("date"),
vl.color().average("tmax").scale({ scheme: "redyellowblue", reverse: true }),
// vl.size().average("precip")
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
commits = FileAttachment("github.csv").csv()
Insert cell
viewof punchCard = vl.markCircle()
.data(commits)
.encode(
vl.y().fieldO("time").timeUnit("day"), // .sort(["mon", "tue", "wed", "thu", "fri", "sat", "sun"]),
vl.x().fieldO("time").timeUnit("hours"),
vl.size().sum("count") //.scale({ range: [0, 200] })
)
.render()
Insert cell
Insert cell
Insert cell
viewof tableText = vl.markText()
.data(weather)
.encode(
vl.row().fieldO("date").timeUnit("utcyear"),
vl.y().fieldO("date").timeUnit("utcmonth"),
vl.x().fieldO("date").timeUnit("utcdate"),
vl.text().fieldN("condition")
)
.width(860)
.config({axisLeft: {title: null}, header: {title: null}})
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
airports = FileAttachment("airports.csv").csv()
Insert cell
airports[0]
Insert cell
viewof geoScatter = vl.markSquare({ size: 3 })
.data(airports)
.project(vl.projection("albersUsa")) // "Albers USA" includes an inset for Alaska and Hawaiʻi
// .project(vl.projection("orthographic").rotate([70, -10]))
.encode(
vl.longitude().fieldQ("longitude"),
vl.latitude().fieldQ("latitude"),
vl.color().fieldN("state").legend(false), // Color by state, but don’t need a legend
vl.tooltip("name")
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof geoScatterFeatures = {
// Landmass for the U.S.
const landmass = vl.markGeoshape()
// Get the shape for the U.S. from the us-atlas npm module.
.data(vl.topojson("https://unpkg.com/us-atlas@3/nation-10m.json").feature("nation"))
.encode(
vl.stroke().value("lightgray"),
vl.color().value(null)
);

// The previous visualization
const points = vl.markCircle({ size: 3 })
.data(airports)
.encode(
vl.longitude().fieldQ("longitude"),
vl.latitude().fieldQ("latitude"),
vl.color().fieldN("state").legend(false)
);
// Return a combined view
return vl
.layer(landmass, points) // Layer the views together.
.project(vl.projection("albersUSA"))
.render();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { hale } from "@d3/world-choropleth"
Insert cell
lifeExpectancy = new Map(hale.map(d => [d.name, d.hale]))
Insert cell
viewof choropleth = vl.markGeoshape()
.data(vl.topojson("https://unpkg.com/world-atlas@2/countries-110m.json").feature("countries"))
.transform( // Transform is advanced
vl.lookup("properties.name").from( // Lookup is even more advanced
vl.lookupData(Array.from(lifeExpectancy.entries())).key("0").fields("1")
).as("life expectancy")
)
.project(vl.projection("equalEarth"))
.encode(
vl.color().fieldQ("life expectancy").legend({ orient: "top" }),
vl.tooltip(["properties.name", "life expectancy"])
)
.width(width)
.height(width / 2.5)
.autosize({ type: "fit-x", contains: "padding" })
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
import { tryIt } from "3c458cfcac4dbda8"
Insert cell
d3.utcDay()
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