Public
Edited
Apr 1, 2023
Insert cell
Insert cell
Insert cell
{
const plot1 = vl
.markBar({ filled: true })
.transform(
vl
.aggregate({ sum_votos: "sum(votos)" })
.groupby(["candidato", "comuna"]),
vl
.window([{ op: "row_number", as: "ranking" }])
.sort([{ field: "sum_votos", order: "descending" }])
.groupby(["comuna"]),
vl
.calculate("datum.ranking <= 5 ? datum.candidato : 'otros'")
.as("candidato_filtrado")
)
.encode(
vl
.x()
.fieldN("comuna")
.axis({ title: "Comuna" })
.sort({ op: "sum", field: "votos", order: "descending" }),
vl.y().fieldQ("sum_votos").axis({ title: "Votación" }),
vl.color().fieldN("candidato_filtrado").title("Candidato").legend(null)
)
.width(width)
.height(300);

return plot1
.data(al)
.autosize({ type: "fit-x", contains: "padding" })
.render();
}
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
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