Published
Edited
Dec 9, 2021
4 stars
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
// add rule to show difference: actuals to forecast
// then comment out Plot.line sections to remove the lines
// then switch the ruleX to y1: 0 and y2: d => d.actuals - d.forecast

/*
Plot.ruleX(data, {
x: "date",
y1: "actuals",
y2: "forecast",
stroke: d => d.actuals > d.forecast
}),
*/

// show the actual demand
Plot.line(data, {
x: "date",
y: "actuals",
stroke: "#5b6187"
}),

// dashed partially line to show the day-ahead forecasted demand
Plot.line(data, {
x: "date",
y: "forecast",
strokeDasharray: "2 2",
stroke: "#a2a5ba"
}),

// vertical rule to mark date/time of event
Plot.ruleX([event.datetime], {
stroke: "black",
strokeWidth: 1
}),

// rule at bottom of chart marking y=0;
Plot.ruleY([0]),

],

// making ticks readable / in appropriate timezone
x: {
ticks: d3
.utcWeeks(...d3.extent(data, (d) => d.date))
.map((d) => d3.utcHour.offset(d, 6)),
tickFormat: (d) =>
d.toLocaleString("en-US", {
timeZone: "America/Chicago",
month: "short",
day: "numeric"
})
},
marginLeft: 50,
marginRight: 100,
width
})
Insert cell
Insert cell
Insert cell
maxValue = Math.max(d3.max(data, d => d.actuals), d3.max(data, d => d.forecast))
Insert cell
rawdata = FileAttachment("TexasEnergyDemandForecast-1.csv").csv({typed: true})
Insert cell
data = aq.from(rawdata) // https://observablehq.com/@observablehq/data-wrangler
.rename({demand: "actuals"}) // rename column from “demand” to “actuals”
.objects() // return an array of objects
Insert cell
event = ({
description: "Rolling Blackouts",
datetime: new Date("2021-02-15T07:25:00Z") // 7:25AM UTC is 1:25AM CST
})
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