Published
Edited
Oct 15, 2019
4 forks
Importers
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
// average hours of sunshine per year, courtesy of https://usclimatedata.com/ and https://en.wikipedia.org/wiki/List_of_cities_by_sunshine_duration (for Pittsburgh)
sun = ({
"Pittsburgh": [94,109,155,183,217,242,255,228,197,167,99,74],
"Seattle": [69,108,178,207,253,268,312,281,221,142,72,52],
"Chicago": [135,136,187,215,281,311,318,283,226,193,113,106],
"New York": [154,171,213,237,268,289,302,271,235,213,169,155],
"San Francisco": [165,182,251,281,314,330,300,272,267,243,189,156],
"Houston": [144,141,193,212,266,298,294,281,238,239,181,146],
"Miami": [222,227,266,275,280,251,267,263,216,215,212,209]
})
Insert cell
// latitude and longitude values, courtesy of https://www.latlong.net/
ll =({
"Pittsburgh": [40.440624, -79.995888],
"Seattle": [47.608013, -122.335167],
"Chicago": [41.881832, -87.623177],
"New York": [40.730610, -73.935242],
"San Francisco": [37.733795, -122.446747],
"Houston": [29.749907, -95.358421],
"Miami": [25.761681, -80.191788]
})
Insert cell
// the months of the year in abbreviated English
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
Insert cell
// wrangle it all together!
data = Object.keys(sun).reduce((data, city) => {
return data.concat(sun[city].map((d,i) => {
return {
city: city,
lon: ll[city][1],
lat: ll[city][0],
month: months[i],
monthnum: i,
sunshine: d
};
}))
}, []);
Insert cell
Insert cell
Insert cell
Insert cell
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