{
const svg = d3.create('svg')
.attr('width', totalWidth).attr('height', totalHeight);
const x = d3.scaleLinear()
.domain([0, d3.max(data, d => d.population)]).nice()
.range([0, visWidth]);
const y = d3.scaleBand()
.domain(data.map(d => d.country))
.range([0, visHeight])
.padding(0.2);
const g = svg.append("g")
.attr('transform', `translate(${margin.left}, ${margin.top})`);
const xAxis = d3.axisBottom(x).tickFormat(format);
const yAxis = d3.axisLeft(y);
g.append('g').call(yAxis);
g.append('g')
.attr('transform', `translate(0, ${visHeight})`)
.call(xAxis)
.append('text')
.attr('fill', 'black')
.attr('x', visWidth / 2)
.attr('y', 40)
.text("Population");
g.selectAll('rect')
.data(data)
.join('rect')
.attr('x', 0)
.attr('y', d => y(d.country))
.attr('width', d => x(d.population))
.attr('height', y.bandwidth())
.attr('fill', 'steelblue');
return svg.node();
}