{
const svg = d3.create('svg')
.attr('width', totalWidth).attr('height', totalHeight);
const x = d3.scaleTime()
.domain(domains.x)
.range([0, visWidth]);
const row = d3.scaleBand()
.domain(domains.groups)
.range([0, visHeight])
.paddingInner(0.25);
const y = d3.scaleLinear()
.domain(domains.y).nice()
.range([row.bandwidth(), 0]);
const color = d3.scaleOrdinal()
.domain(domains.groups)
.range(d3.schemeTableau10);
const area = d3.area()
.x(d => x(d.year))
.y1(d => y(d.unemp))
.y0(d => y(0));
const g = svg.append("g")
.attr('transform', `translate(${margin.left}, ${margin.top})`);
const rows = g.append('g')
.selectAll('g')
.data(linedata)
.join('g')
.attr('transform', d => `translate(0, ${row(d.populationgroup)})`)
.attr('fill', d => color(d.populationgroup))
const xAxis = d3.axisBottom(x).tickFormat(d3.timeFormat('%Y'));
const yAxis = d3.axisLeft(y).ticks(5);
g.append('g')
.attr('transform', `translate(0, ${visHeight})`)
.call(xAxis);
rows.append('g')
.attr('class', 'y-axis')
.call(yAxis)
.call(g => g.select('.domain').remove());
rows.append('text')
.text(d => d.populationgroup)
.attr('font-size', 12)
.attr('fill', 'black')
.attr('font-family', 'sans-serif')
.attr('y', -5)
.attr('x', 5);
g.select('.y-axis')
.append('text')
.attr('fill', 'black')
.attr('text-anchor', 'start')
.attr('dominant-baseline', 'middle')
.attr('y', 7)
.attr('x', 5)
.text('Unemployment %');
rows.append('path')
.attr('d', d => area(d.values));
return svg.node();
}