Plot.plot({
width,
height: 500,
x: {},
y: {
domain: [-1, 1],
axis: null
},
marks: [
Plot.tip(dados, { x: "Itabaiana", y: 0.8 }),
Plot.text(
dados.filter((d) => d.mudanca_pct > 0),
{
x: "nome_municipio",
y: "mudanca_pct",
text: (d) => "▲" + d3.format(".1%")(d.mudanca_pct),
dy: -10,
textAnchor: "center",
fontFamily: "Roboto",
fontSize: 12,
fontWeight: "bold"
}
),
Plot.text(
dados.filter((d) => d.mudanca_pct < 0),
{
x: "nome_municipio",
y: "mudanca_pct",
text: (d) => "▼" + d3.format(".1%")(d.mudanca_pct * -1),
dy: 10,
textAnchor: "center",
fontFamily: "Roboto",
fontSize: 12,
fontWeight: "bold"
}
),
Plot.barY(dados, {
x: "nome_municipio",
y: "mudanca_pct",
tip: true,
sort: { x: "y", reverse: true },
fill: (d) => (d.mudanca_pct < 0 ? "#e76f51" : "#2a9d8f")
}),
Plot.ruleY([0])
]
})