Published
Edited
Jul 7, 2022
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(input_data)
.encode(
vl.y().fieldQ(y_title),
vl.x().fieldQ(x_title),
vl.color().fieldN(legend)
)
.render()
Insert cell
input_data = irisData
Insert cell
y_title = 'petalLength'
Insert cell
x_title = 'petalWidth'
Insert cell
legend = 'species'
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
dataSubset = input_data
.filter(data =>
data[specified_feature_1] >= sepalLengthLimits[0] &&
data[specified_feature_1] <= sepalLengthLimits[1])
.filter(data =>
data[specified_feature_2] >= sepalWidthLimits[0] &&
data[specified_feature_2] <= sepalWidthLimits[1])
Insert cell
specified_feature_1 = "sepalLength"
Insert cell
specified_feature_2 = "sepalWidth"
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