{
let thevariable = {variable: 'outflow_per_capita'}
let thedata = federal_outflows.filter(d => d.outflow_per_capita < 0)
thedata = aq.from(thedata)
.derive({
'outflow_per_capita': d => d.outflow_per_capita*-1
})
.derive({
'below_pr': d => d.outflow_per_capita > 10300,
})
let eitc_promedio = aq.from(thedata)
.rollup({
'outflow_per_capita': op.mean('outflow_per_capita')
})
.objects()[0]['outflow_per_capita']
let state_labels = {
'District of Columbia': 'District of\nColumbia',
}
let theplot = Plot.plot({
marginLeft: 160,
marginBottom: 50,
height: 700,
marks: [
Plot.axisX({
fontFamily: 'jaf-bernino-sans',
fontVariant: 'tabular-nums',
tickSize: 0,
fontSize: 16,
tickFormat: '$,.0s',
label: 'Deficits in Net Federal Expenditures per Capita',
}),
Plot.axisY({
reverse: true,
label: null,
fontFamily: 'jaf-bernino-sans',
tickSize: 0,
fontSize: 16,
// rotate: -90,
// reverse: true,
// tickSpacing: .3,
// tickPadding: 30,
textAnchor: 'end', lineAnchor: 'middle',
// tickFormat: d => state_labels[d] ?? d,
}),
Plot.ruleX([eitc_promedio]),
Plot.barX(thedata, {
x: thevariable.variable,
y: 'state',
// fill: EA_COLORES_MAP['INDIGO'],
fill: d => d.state === 'Puerto Rico' ? EA_COLORES_MAP['INDIGO'] : (
d.below_pr ? chroma(EA_COLORES_MAP['GREEN']).alpha(0.35).hex() : '#cdd1ec'
),
// opacity: d => d['País'] === 'Puerto Rico (2023'
sort: {y: "x", reverse: true},
}),
// Plot.ruleX([credito_promedio]),
// Plot.text(thedata, {
// filter: d => d[thevariable.variable] < 0,
// fontFamily: 'jaf-bernino-sans',
// fontVariant: 'tabular-nums',
// fontWeight: 'bold',
// fontSize: 14.5,
// y: thevariable.variable,
// x: 'state',
// fill: d => d.state === 'Puerto Rico' ? 'black' : 'black',
// text: d => d3.format('$,.0f')(d[thevariable.variable]),
// // dx: -5,
// // textAnchor: 'end',
// sort: {x: "y", reverse: true}}),
Plot.text(thedata, {
filter: d => d[thevariable.variable] >= 30000,
fontFamily: 'jaf-bernino-sans',
fontVariant: 'tabular-nums',
fontWeight: 'bold',
fontSize: 14.5,
x: thevariable.variable,
// rotate: -90,
y: 'state',
fill: d => d.state === 'Puerto Rico' ? 'black' : 'black',
text: d => d3.format('$,.0f')(d[thevariable.variable]),
dx: -5,
textAnchor: 'end',
// dy: 8,
// sort: {y: "x", reverse: false},
}),
Plot.text(thedata, {
filter: d => d[thevariable.variable] < 30000,
fontFamily: 'jaf-bernino-sans',
fontVariant: 'tabular-nums',
fontWeight: 'bold',
fontSize: 14.5,
x: thevariable.variable,
// rotate: -90,
y: 'state',
fill: d => d.state === 'Puerto Rico' ? 'black' : 'black',
text: d => d3.format('$,.0f')(d[thevariable.variable]),
dx: 5,
stroke: 'white', strokeWidth: 6,
textAnchor: 'start',
// dy: -8,
// sort: {y: "x", reverse: false},
}),
Plot.text([0], {
x: eitc_promedio,
dx: 5,
// dy: -8,
y: d => 'Idaho',
text: d => `Average\n${d3.format('$,.0f')(eitc_promedio)}`,
textAnchor: 'start',
lineAnchor: 'bottom',
fontFamily: 'jaf-bernino-sans',
fontWeight: 'bold',
fontSize: 13,
}),
]
})
// console.log('ugh', theplot)
add_estilos(theplot, 'somebar')
return theplot
}