scatterplot = {
const margin = { top: 20, right: 20, bottom: 50, left: 50 },
width = 500 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
const svg = d3
.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
const g = svg
.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
const x = d3
.scaleLinear()
.domain([0, d3.max(output, (d) => d.number_of_players)])
.range([0, width]);
const y = d3
.scaleLinear()
.domain([16, d3.max(output, (d) => d.average_age)])
.range([height, 0]);
g.append("g")
.attr("transform", `translate(0,${height})`)
.call(d3.axisBottom(x));
g.append("g").call(d3.axisLeft(y));
g.append("text")
.attr("x", width / 2)
.attr("y", height + margin.bottom - 10)
.attr("text-anchor", "middle")
.attr("class", "axis-label")
.text("Number of Players");
g.append("text")
.attr("x", -height / 2)
.attr("y", -margin.left + 15)
.attr("text-anchor", "middle")
.attr("class", "axis-label")
.attr("transform", "rotate(-90)")
.text("Average Age");
const color = d3
.scaleSequential(d3.interpolateViridis)
.domain([0, d3.max(output, (d) => d.number_of_players)]);
g.selectAll(".dot")
.data(output)
.join("circle")
.attr("class", "dot")
.attr("cx", (d) => x(d.number_of_players))
.attr("cy", (d) => y(d.average_age))
.attr("r", 5)
.attr("fill", (d) => color(d.number_of_players))
.append("title")
.text((d) => d.nationality);
return svg.node();
}