Published
Edited
May 12, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { meteorites_autoTyped } from "@clokman/import-data"
Insert cell
Insert cell
Inputs.table(meteorites_autoTyped)
Insert cell
Insert cell
Insert cell
meteorites = aq
.from(meteorites_autoTyped)
.select("name", "mass", "fall", "year")
//.sample(10_000) // uncomment if your computer is slowing down
.rename({ mass: "massInGrams" }) // uncomment later
.derive({ mass: (d) => d.massInGrams / 1000000 }) // uncomment later
.objects()
// ... include only 'name', 'mass', 'fall', and 'year' columns
// ... sample 20.000 or 10.000 cells, especially if your computer is slowing down
// ... rename 'mass' column to 'massInGrams'
// ... create a new 'mass' column, which holds the masses as units of tons
Insert cell
Insert cell
Inputs.table(meteorites)
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [Plot.dot(meteorites, { x: "year", y: "mass" })]
})
Insert cell
Insert cell
Plot.plot({
marks: [Plot.dot(meteorites, { x: "year", y: "mass", r: "mass" })]
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, { x: "year", y: "mass", r: "mass", fill: "mass" })
]
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, { x: "year", y: "mass", r: "mass", fill: "fall" })
]
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
r: "mass",
fill: "fall",
fillOpacity: 0.5
})
]
})
Insert cell
Insert cell
Plot.plot({
color: { legend: true },
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
r: "mass",
fill: "fall",
fillOpacity: 0.5
})
]
})
Insert cell
Insert cell
Plot.plot({
color: { legend: true },
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
r: "mass",
fill: "mass",
fillOpacity: 0.5
})
]
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
r: "mass",
fill: "mass",
fillOpacity: 0.5
}),

Plot.text(meteorites, {
x: 1470,
y: 10,
text: ["Hallo ->"],
fontSize: 25,
fill: "red"
})
]
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
r: "mass",
fill: "mass",
fillOpacity: 0.5
}),

Plot.text(meteorites, {
x: "year",
y: "mass",
text: "name",
fontSize: 10
})
]
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
r: "mass",
fill: "mass",
fillOpacity: 0.5
}),

Plot.text(meteorites, {
filter: (d) => d.mass > 5,
x: "year",
y: "mass",
text: "name",
fontSize: 10
})
]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
r: 2,
fill: "dodgerBlue",
opacity: 0.5
})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
// skipped in class
Insert cell
Insert cell
Insert cell
Insert cell
regression = require('d3-regression')
Insert cell
Insert cell
linearRegression = regression.regressionLinear()
.x(d => d.year)
.y(d => d.mass)
Insert cell
Insert cell
trendLine = linearRegression(meteorites) // please uncommment after 'meteorites' variable is declared
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
r: 2,
opacity: 0.5,
fill: "dodgerBlue"
}),
Plot.link([0], {
x1: trendLine[0][0],
y1: trendLine[0][1],
x2: trendLine[1][0],
y2: trendLine[1][1],
stroke: "salmon"
})
]
})
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
linearRegression_usingDateColumn = regression.regressionLinear()
.x(d => d.date)
.y(d => d.mass)
Insert cell
Insert cell
// trendLine2 = linearRegression_usingDateColumn(meteoritesWithDates)
Insert cell
Insert cell
Insert cell
// ...
Insert cell
Insert cell
Insert cell
Insert cell
// ...
Insert cell
Insert cell
// Inputs.table(meteorites_fixed) // please uncomment
Insert cell
Insert cell
// trendLine3 = linearRegression_usingDateColumn(meteorites_fixed) // please uncomment
Insert cell
Insert cell
// Please uncomment the following code
//
//
// Plot.plot({
// y: {
// label: '↑ Mass in Tons',
// grid: true
// },
// x: {
// label: 'Year →',
// },
// marks: [
// // Values based on linear regression
// Plot.link([0], {
// x1: trendLine3[0][0],
// y1: trendLine3[0][1],
// x2: trendLine3[1][0],
// y2: trendLine3[1][1],
// stroke: 'salmon'
// }),
// Plot.dot(meteorites_fixed, {
// x: "date",
// y: "mass",
// fill: 'dodgerblue',
// fillOpacity: 0.5
// })
// ]
// })
Insert cell
Insert cell
Insert cell
// You can uncomment the following code after 'meteorites' variable is declared
//
// meteoritesWithMapDates = meteorites.map( ({ name, fall, year, mass }) => ({
// name: name,
// year: new Date(year, 1, 1),
// fall: fall,
// mass: +mass
// }) )
Insert cell
// You can uncomment the following code after 'meteoritesWithMapDates' and 'trendLine3' variables are declared

// Plot.plot({
// y: {
// label: '↑ Mass in Tons',
// grid: true
// },
// x: {
// label: 'Year →',
// },
// marks: [
// Plot.dot(meteoritesWithMapDates, {
// x: "year",
// y: "mass",
// fill: 'dodgerblue',
// fillOpacity: 0.5
// }),
// // Values based on linear regression
// Plot.link([0], {
// x1: trendLine3[0][0],
// y1: trendLine3[0][1],
// x2: trendLine3[1][0],
// y2: trendLine3[1][1],
// stroke: 'salmon'
// })
// ]
// })
Insert cell
Insert cell
Insert cell
import {imageToDo} from "@clokman/student-blocks"
Insert cell
imageToDo
Insert cell
import {toc} from "@nebrius/indented-toc"
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