Public
Edited
Apr 1, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mtwash = await aq.loadCSV(
"https://raw.githubusercontent.com/arkraieski/mtWashington/dev/data-raw/mtWashington.csv"
)
Insert cell
mtwash.view()
Insert cell
mtwash.count().view()
Insert cell
Insert cell
Insert cell
mtwash
.derive({
year: aq.escape(d => d.Date.getFullYear())
})
.groupby('year')
.rollup({ min_temp: d => op.min(d["Min.temperature"])})
.view()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks:
[
Plot.lineY(tempPlotData, {x: "Date", y: plotVariable}),
Plot.ruleY([0])
]
})
Insert cell
tempPlotData = mtwash2
.params({startDate: startDate,
endDate: endDate}) // .params lets us bring the inputs into the arquero table stuff
.filter(d => d.Date >= startDate & d.Date <= endDate)
Insert cell
Insert cell
Plot.plot({
x:{
domain: monthNames
},
marks: [
Plot.boxY(mtwash2, {x: "month", y: boxplotVariable})
]
})
Insert cell
Insert cell
tempLmPlot = Plot.plot({
x: {tickFormat: "d"},
marks: [
Plot.dot(avg_temp_by_year, {x: "year", y: "annualAverageTemp"}),
Plot.line(avg_temp_by_year, {x: "year", y: "annualAverageTemp"}),
Plot.linearRegressionY(avg_temp_by_year, {x: "year", y: "annualAverageTemp", stroke: "steelblue", ci: 0.95})
]
})
Insert cell
Insert cell
avg_temp_by_year = mtwash
.derive({
year: aq.escape(d => d.Date.getFullYear())
})
.groupby("year")
.rollup({annualAverageTemp:d => op.mean(d["Avg.temperature"])})
.filter(d => d.year > 2004 && d.year < 2023) // 2023
Insert cell
Insert cell
precipByYear = mtwash
.derive({
year: aq.escape(d => d.Date.getFullYear())
})
.groupby("year")
.rollup({total_precipitation: d => op.sum(d["Total.equiv.precipitation"])})
.filter(d => d.year > 2004 && d.year < 2023 ) // first day of 2005 was being counted as part of 2004??
Insert cell
Plot.plot({
x: {tickFormat: "d"},
y: {label: "Precipitation (in.)"},
marks: [
Plot.barY(precipByYear, {x: "year", y: "total_precipitation"}),
Plot.ruleY([0]),
Plot.linearRegressionY(precipByYear, {x: "year", y: "total_precipitation", stroke: "steelblue", ci: 0.95})
]
})
Insert cell
Insert cell
viewof selectedMonth = Inputs.select(monthNames, {label: "month"})
Insert cell
Insert cell
Plot.plot({
x: {tickFormat: "d"},
y: {label: "Precipitation (in.)"},
marks: [
Plot.barY(precipMonthYear, {x: "year", y: "total_precipitation"}),
Plot.ruleY([0]),
Plot.linearRegressionY(precipMonthYear, {x: "year", y: "total_precipitation", stroke: "steelblue", ci: 0.95})
]
})
Insert cell
Plot.plot({
x: {
domain: monthNames
},
marks:
[
Plot.boxY(monthly_totals, {x: "month", y: "total_precipitation"})
]
})
Insert cell
monthly_totals = mtwash2
.groupby(['year', "month"])
.rollup({
total_precipitation: d => op.sum(d["Total.equiv.precipitation"])
})
Insert cell
precipMonthYear = mtwash2
.params({selectedMonth: selectedMonth})
.filter(d => d.month == selectedMonth)
.groupby('year')
.rollup({total_precipitation: d => op.sum(d["Total.equiv.precipitation"])})
Insert cell
mtwash2 = mtwash
.params({ monthNames: monthNames })
.derive({ month: (d, $) => $.monthNames[op.month(d.Date)],
year: aq.escape(d => d.Date.getFullYear()),
// see appendix for windchill() function
Avg_windchill_temperature: aq.escape(d => windchill(d["Avg.temperature"], d["Avg.wind.speed"]))})

Insert cell
Insert cell
Insert cell
Insert cell
windchill = function(T, V){
if (T <= 50 && V >= 3){ //windchill isn't defined outside these conditions
return( 35.74 + 0.6125 * T - 35.75 * Math.pow(V, 0.16) + 0.4275 * T * Math.pow(V, 0.16));
} else{
return(NaN)
}
}
Insert cell
Insert cell
vl
.markLine() // the first two lines are akin to ggplot(data = penguins) + geom_point
.data(mtwash)
.encode( // encode is like aes
vl.x().fieldQ('Date') // aes(x = body_mass_g)
//.scale({domain: [2000, 6500]}) // modify scale attributes, similar to scale_x_axis
.axis({title: "Date"}),
vl.y().fieldQ('Avg.temperature'),
//.scale({domain: [30, 60]}),
vl.tooltip(['total.equiv.precipitation', 'Fastest.wind.speed']) // tooltips for free!
).render()
Insert cell
vg = require('vega-lite')
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