plot_region = (region, figheight=200) => {
const endDate = new Date(2023,1,0)
const data_region = data.
filter(aq.escape(d => d.region == region && d.date < endDate)).
groupby('date').
pivot('nivel', 'porcentaje').
derive({'total': d => d[0] + d[1] + d[2] + d[3] + d[4]}).
derive({
0: d => d[0] / d['total'],
1: d => d[1] / d['total'],
2: d => d[2] / d['total'],
3: d => d[3] / d['total'],
4: d => d[4] / d['total']}).
fold(['0','1','2','3','4']).
derive({key: aq.escape(d => Number(d.key))})
return Plot.plot({
width: width,
height: figheight,
marginLeft: 0,
marginRight: 0,
marginBottom: 0,
marginTop: 0,
style: {
background: '#e7dfd2'
},
color: {
range: ['#d9cebaa3', '#524133'],
interpolate: d3.interpolateRgb.gamma(2.2),
reverse: false,
legend: false,
},
x: {
axis: null,
},
y: {
axis: null,
},
marks: [
Plot.areaY(
data_region,
Plot.stackY({
x: "date",
y: "value",
fill: "key",
opacity: .7
})
)
]
})
}