Published
Edited
Jan 4, 2022
5 forks
96 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
fullText = FileAttachment("iris_data.csv").text()
Insert cell
Insert cell
lines = (await FileAttachment("iris_data.csv").text()).split('\n')
Insert cell
Insert cell
Insert cell
Insert cell
(await FileAttachment("iris_data.csv").text()).split('\n').map(line => line.split(','))
Insert cell
Insert cell
d3 = require("d3-dsv@1")
Insert cell
Insert cell
irisData = d3.csvParse(await FileAttachment("iris_data.csv").text(), d3.autoType)
Insert cell
Insert cell
irisData
Insert cell
Insert cell
Inputs.table(irisData)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
irisData.filter(d => d.species === 'virginica').map(d => d.petalLength)
Insert cell
Insert cell
{
const results = [];
for (const datum of irisData) {
if (datum.petalLength < 4) {
results.push(datum)
}
}
return results;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
vegaPetals = vl
.markPoint()
.data(irisData)
.encode(
vl.y().fieldQ("petalLength"),
vl.x().fieldQ('petalWidth'),
vl.color().fieldN('species')
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
petalLengths = irisData.map(sample => sample.petalLength)
Insert cell
import { chart } with { petalLengths as data } from "@d3/histogram"
Insert cell
chart
Insert cell
Insert cell
simpleHtml = {
const sigils = {
setosa: '🌸',
versicolor: '🌼',
virginica: '🌺',
};
const sortedIrises = irisData.slice(0); // note making a copy here to sort
// because mutation of data from other cells is frowned upon in Observable
sortedIrises.sort((a, b) => a.petalLength - b.petalLength)
const flowers = sortedIrises.map(flower => html`
<span style="font-size: ${flower.petalLength * scale}px">${sigils[flower.species]}</span>`)
return html`<div style="height: 300px; overflow: scroll;">${flowers}</div>`
}
Insert cell
Insert cell
viewof scale = slider({min: 1, max: 20, value:7, step: 0.5})
Insert cell
md`**Plot**: The fastest way to make a useful, great-looking plot in Observable is to use [Plot](https://observablehq.com/@observablehq/plot).`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
irisSubset = irisData
.filter(flower =>
flower.sepalLength >= sepalLengthLimits[0] &&
flower.sepalLength <= sepalLengthLimits[1])
.filter(flower =>
flower.sepalWidth >= sepalWidthLimits[0] &&
flower.sepalWidth <= sepalWidthLimits[1])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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