{
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const iWidth = width - margin.left - margin.rigth;
const iHeight = height - margin.top - margin.bottom;
const xScale = d3
.scaleLinear()
.domain(d3.extent(penData, (d) => d[xAttrName]))
.range([0, iWidth])
.nice();
const yScale = d3
.scaleLinear()
.domain(d3.extent(penData, (d) => d[yAttrName]))
.range([iHeight, 0])
.nice();
const cScale = d3
.scaleOrdinal(d3.schemeCategory10)
.domain(new Set(penData.map((e) => e.species)).values());
const g = svg
.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
g.append("g")
.attr("transform", `translate(0,${iHeight})`)
.call(d3.axisBottom(xScale));
g.append("g").call(d3.axisLeft(yScale));
g.selectAll("circle")
.data(penData)
.join("circle")
.attr("fill", (d) => cScale(d.species))
.attr("cx", (d) => xScale(d[xAttrName]))
.attr("cy", (d) => yScale(d[yAttrName]))
.attr("r", 3);
return svg.node();
}