Published
Edited
Jun 6, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { meteorites_autoTyped } from "@clokman/import-data"
Insert cell
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()
Insert cell
Insert cell
Insert cell
Inputs.table(meteorites)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [Plot.dot(meteorites, { x: "year", y: "mass" })]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [Plot.dot(meteorites, { x: "year", y: "mass", r: "mass" })]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, { x: "year", y: "mass", r: "mass", fill: "mass" })
]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, { x: "year", y: "mass", r: "mass", fill: "fall" })
]
})
Insert cell
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
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
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
Insert cell
Plot.plot({
color: { legend: true },
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
r: "mass",
fill: "mass",
fillOpacity: 0.5
}),

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

Plot.text(meteorites, {
x: 1470,
y: 10,
text: ["Hello ->"],
fontSize: 25,
fill: "red"
})
]
})
Insert cell
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
//fill: "red"
})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
fill: "dodgerBlue",
r: 2,
opacity: 1 //since I didn't see anything for opacity 0.05 I put it on 1
})
]
})
Insert cell
Insert cell
Insert cell
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
Insert cell
Plot.plot({
marks: [
Plot.dot(meteorites, {
x: "year",
y: "mass",
fill: "dodgerBlue",
r: 2
}),

Plot.link([0], {
x1: trendLine[0][0],
y1: trendLine[0][1],
x2: trendLine[1][1],
y2: trendLine[1][0],
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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more