{
const clothing = data.filter(d => d.Category === "Clothing" && d.SalesTerritoryCountry === "United States");
const bts = [...new Set(clothing.map(d => d.BusinessType))];
const plot = Plot.plot({
width: width,
marginLeft: 80,
height: 600,
grid: true,
x: {type: "log", nice: true, tickFormat: ","},
y: {
label: "subcategory",
domain: d3.groupSort(clothing, g => -d3.sum(g, d => d.SalesAmount), d => d.Subcategory),
inset: 5
},
fy: {
label: "region",
domain: d3.groupSort(clothing, g => -d3.sum(g, d => d.SalesAmount), d => d.SalesTerritoryRegion)
},
color: {
domain: bts,
type: "categorical"
},
facet: {
data: clothing,
y: "SalesTerritoryRegion",
marginRight: 70
},
marks: [
Plot.frame(),
Plot.dot(clothing, Plot.groupY({x: "sum"}, {x: "SalesAmount", y: "Subcategory", stroke: "BusinessType"}))
]
});
return wrap(
Swatches({color: d3.scaleOrdinal(bts, d3.schemeTableau10)}),
plot
);
}