Public
Edited
Dec 1, 2023
17 forks
Insert cell
Insert cell
Insert cell
Plot.plot({
marginLeft: 80,
x:{domain:[new Date(`${year}-01-01`),new Date(`${year}-12-01`)]},
y:{domain:[0,700000]},
marks:[
Plot.ruleX([new Date('1992-01-01')]),
Plot.ruleY([0]),
Plot.line(retail,{x:'sales_month',y:'sales'})
]
})
Insert cell
Plot.plot({
marginLeft: 80,
x:{domain:[new Date(`1992-01-01`),new Date(`2020-12-01`)]},
y:{domain:[0,60000]},
marks:[
Plot.ruleX([new Date('1992-01-01')]),
Plot.ruleY([0]),
Plot.line(retail2,{x:'yr',y:'total',filter:d => d.kind_of_business == 'Sporting goods stores',strokeDasharray:'5,5'}),
Plot.line(retail2,{x:'yr',y:'total',filter:d => d.kind_of_business == 'Hobby, toy, and game stores',strokeDasharray:'1,5'}),
Plot.line(retail2,{x:'yr',y:'total',filter:d => d.kind_of_business == 'Book stores'}),
Plot.text(['Sporting goods stores'],{x:new Date('2019'),y: 55000}),
Plot.text(['Hobby, toy, and game stores'],{x:new Date('2018'),y: 15000}),
Plot.text(['Book stores'],{x:new Date('2020'),y: 5000})
]
})
Insert cell
Plot.plot({
marginLeft: 80,
x:{domain:[new Date(`1992-01-01`),new Date(`2020-12-01`)]},
y:{domain:[0,60000]},
marks:[
Plot.ruleX([new Date('1992-01-01')]),
Plot.ruleY([0]),
Plot.line(retail3,{x:'yr',y:'sporting'}),
Plot.line(retail3,{x:'yr',y:'hobby'}),
Plot.line(retail3,{x:'yr',y:'books'}),
]
})
Insert cell
db
SELECT sales_month,sales
from sales
WHERE kind_of_business = 'Retail and food services sales, total' AND date_part('year',sales_month) = ${year}
Insert cell
db
SELECT min(sales_month) as yr, sum(sales) as total, date_part('year',sales_month) as part,kind_of_business
FROM sales
WHERE kind_of_business in ('Sporting goods stores','Hobby, toy, and game stores', 'Book stores' )
GROUP BY kind_of_business,part
ORDER BY part
Insert cell
db
SELECT min(sales_month) as yr,
sum(sales) as total,
sum(
CASE kind_of_business
WHEN 'Sporting goods stores' then sales
ELSE 0
END
) sporting,
sum(
CASE kind_of_business
WHEN 'Hobby, toy, and game stores' then sales
ELSE 0
END
) hobby,
sum(
CASE kind_of_business
WHEN 'Book stores' then sales
ELSE 0
END
) books,
FROM sales
WHERE kind_of_business in ('Sporting goods stores','Hobby, toy, and game stores', 'Book stores' )
GROUP BY date_part('year',sales_month)
Insert cell
d3.max(retail2,d => d.total)
Insert cell
db = DuckDBClient.of({
sales:sales
})
Insert cell
sales = FileAttachment("us_retail_sales.csv").csv({typed:true})
Insert cell
db
SELECT DISTINCT kind_of_business
FROM sales
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