Public
Edited
Mar 2, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
x: {
tickFormat: "d",
ticks:10
},
marks:[
Plot.line(annual_accident_counts, {x: "year", y: "count"}),
Plot.ruleX([2018], {stroke: "red", opacity: haloToggleOpacity}),
Plot.text(["2018 Halo Introduced"], {x: 2009, y: 55, opacity: haloToggleOpacity, fontSize: 12}),
Plot.ruleY([0]),
Plot.linearRegressionY(annual_accident_counts,
{x: "year",
y: "count",
ci: 0.95,
stroke: "steelblue",
opacity: linregToggleOpacity})
]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
x:{
tickFormat: "d"
},
y: {
label: "crash retirements/race"
},
marks: [
Plot.line(hybrid_era_counts, {x: "year", y: "crashRetirementsPerRace", opacity: 0.5}),
// draw a lighter linear regression line over the whole dataset
// and draw 2 linear regression lines colored by "halo" boolean variable
Plot.linearRegressionY(hybrid_era_counts, {x: "year", y: "crashRetirementsPerRace", stroke: "halo"}),
Plot.linearRegressionY(hybrid_era_counts, {x: "year", y: "crashRetirementsPerRace", opacity: 0.3}),
Plot.dot(hybrid_era_counts, {x: "year", y: "crashRetirementsPerRace", fill: "halo",
title: (d) =>
`Year: ${d.year} \n ${d.crashRetirementsPerRace.toPrecision(3)} Crash Retirements / Race`})
],
color: {
legend: true,
type: "categorical",
scheme: "tableau10" //
}
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
annual_accident_counts = aq.from(query)
.params({
plotStart: plotStart
})
.filter(d => op.includes(
["Accident", "Collision", "Collision damage"],
d.status) && d.year >= plotStart)
.groupby("year")
.count()
.ungroup()
.orderby("year")
.derive({
halo: d => d.year >= 2018
})
.derive({
halo: d => d.halo ? "Halo mandated" : "Pre-Halo"
})
Insert cell
hybrid_era_counts = annual_accident_counts.filter(d => d.year >= 2013)
.join(aq.from(raceCounts))
.derive({
crashRetirementsPerRace: d => d.count / d.nRaces
})
Insert cell
hybridEraCountsByRace = aq.from(query)
.filter(d => d.year >= 2013)
.groupby("year", "name")
.rollup({
crash_retirements: d => op.sum(op.includes(["Accident", "Collision", "Collision damage"], d.status))
})
.ungroup()
.derive({
halo: d => d.year >= 2018
})
.derive({
halo: d => d.halo ? "Halo mandated" : "Pre-Halo"
})
.orderby("halo")
Insert cell
hybridEraCountsByRace.view()
Insert cell
Insert cell
Insert cell
// Import Plot with additional tooltip functionality from this notebook
import {Plot} from "@mkfreeman/plot-tooltip"
Insert cell
database = FileAttachment("f1_db.sqlite").sqlite()
Insert cell
database
SELECT res.grid, drivers.driverRef, res.laps, ra.year, ra.name, st.status
FROM results AS res
LEFT JOIN races AS ra
on res.raceId=ra.raceID
LEFT JOIN drivers
on res.driverId=drivers.driverId
LEFT JOIN status AS st
on res.statusId=st.statusId
WHERE st.status NOT IN ("Did not qualify", "Did not prequalify") ;
Insert cell
Insert cell
database
SELECT year, COUNT (*) as nRaces FROM races GROUP BY year
;
Insert cell
Insert cell
database
Type SQL, then Shift-Enter. Ctrl-space for more options.

Insert cell
haloToggleOpacity = {
if(showHaloIntro === false){
return 0;
} else {
return 100;
}
}
Insert cell
linregToggleOpacity = {
if(linearRegToggle === false){
return 0;
} else {
return 100;
}
}
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