{
const svg = d3.create('svg')
.attr('width', visWidth + margin.left + margin.right)
.attr('height', visHeight + margin.top + margin.bottom);
const g = svg.append("g")
.attr('transform', `translate(${margin.left}, ${margin.top})`);
g.selectAll('rect')
.data(data)
.join('rect')
.attr('x', d => countryScale(d.country))
.attr('y', d => populationScale(d.population))
.attr('height',d => visHeight - populationScale(d.population))
.attr('width', countryScale.bandwidth())
.attr('fill', 'steelblue')
.attr('id','bar')
.attr('visibility',barplot)
const line = svg.append('line')
.attr('x1',margin.left)
.attr('x2',visWidth + margin.right + margin.left)
.attr('y1',populationScale(meanPopulation))
.attr('y2',populationScale(meanPopulation))
.attr('stroke-width',1)
.attr('stroke','green')
const meanText = svg.append('text')
.attr('x',margin.left + 100)
.attr('y',populationScale(meanPopulation) + 12)
.attr('fill','red')
.text(`Mean Population is ${d3.format('~s')(meanPopulation)}`)
g.selectAll('circle')
.data(data).join('circle')
.attr('cx',d => countryScale(d.country) + countryScale.bandwidth()/ 2)
.attr('cy',d => populationScale(d.population))
.attr('r', 7)
.attr('fill','yellow')
.attr('id','lolli')
.attr('visibility',lolliplot)
g.selectAll('line')
.data(data).join('line')
.attr('x1',d => countryScale(d.country) + countryScale.bandwidth()/ 2)
.attr('x2',d => countryScale(d.country) + countryScale.bandwidth()/ 2)
.attr('y1',d => populationScale(d.population))
.attr('y2',d => visHeight)
.attr('stroke','yellow')
.attr('id','lolli')
.attr('visibility',lolliplot)
g.append('g')
.call(yAxis)
.call(g => g.select('.domain').remove());
g.append('g')
.attr('transform', `translate(0, ${visHeight})`)
.call(xAxis)
.call(g => g.select('.domain').remove())
.append('text')
.attr('fill', 'black')
.attr('font-family', 'sans-serif')
.attr('x', visWidth / 2)
.attr('y', 40)
.text("Population");
return svg.node();
}