{
const width = 600;
const height = 400;
const margin = {top: 20, right: 20, bottom: 40, left: 40};
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const x = d3.scaleLinear()
.domain(d3.extent(irisData, d => d["sepal_width"]))
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.domain(d3.extent(irisData, d => d["sepal_length"]))
.range([height - margin.bottom, margin.top]);
const color = d3.scaleOrdinal()
.domain(["setosa", "versicolor", "virginica"])
.range(["lightblue", "lightgreen", "orange"]);
svg.append("g")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(6));
svg.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(6));
svg.append("g")
.selectAll("circle")
.data(irisData)
.join("circle")
.attr("cx", d => x(d["sepal_width"]))
.attr("cy", d => y(d["sepal_length"]))
.attr("r", 5)
.attr("fill", d => color(d.species));
svg.append("text")
.attr("x", width / 2)
.attr("y", 15)
.attr("text-anchor", "middle")
.text("Reusable Scatter Plot - Sepal Width vs Sepal Length");
return svg.node();
}