Published unlisted
Edited
Jul 14, 2021
Insert cell
Insert cell
Plot = require(await FileAttachment("plot.umd.min.js").url())
Insert cell
data = FileAttachment("riaa-us-revenue.csv").csv({typed: true})
Insert cell
let's sort by the value
Insert cell
Plot.barX(data, Plot.groupY({ x: "sum" }, {
x: "revenue",
y: "group",
fill: "group",
sortY: true
}))
.plot({
marginLeft: 100
})
Insert cell
Insert cell
Plot.barX(data, Plot.groupY({ x: "sum" }, {
x: "revenue",
y: "group",
fill: "group",
sortY: false
}))
.plot({
marginLeft: 100
})
Insert cell
Insert cell
Plot.barX(data, Plot.groupY({ x: "sum" }, {
x: "revenue",
y: "format",
fill: "group",
sortY: true
}))
.plot({
marginLeft: 250,
})
Insert cell
Insert cell
Plot.barY(data, {
x: "year",
y: "revenue",
fill: "group",
}).plot({
facet: {
data,
y: "group",
marginLeft: 70
},
fy: { label: null },
y: { axis: false },
x: { tickRotate: 90, tickFormat: d => d.getFullYear() },
marks: [ Plot.ruleY([0])],
grid: true,
marginBottom: 70,
width,
height: 400
})
Insert cell
Maybe i want to sort by the maximum of one of the series?
Insert cell
Plot.plot({
marks: [
Plot.barY(data, Plot.stackY({
x: "year",
y: "revenue",
z: "format",
fill: "format",
order: "appearance",
reverse: true,
})),
Plot.ruleY([0])
],
grid: true,
facet: {
data,
y: "group",
marginLeft: 70
},
fy: { label: null },
y: { axis: false },
x: { tickRotate: 90, tickFormat: d => d.getFullYear() },
marginBottom: 70,
width,
})
Insert cell
groups = d3.groupSort(data, v => d3.sum(v, d=> -d.revenue), d => d.group)
Insert cell
formats = d3.groupSort(data, v => d3.sum(v, d=> -d.revenue), d => d.format)
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