iris_scatterplot = {
const width = 500;
const height = 300;
const marginTop = 25;
const marginRight = 20;
const marginBottom = 35;
const marginLeft = 40;
const x = d3
.scaleLinear()
.domain(d3.extent(iris, (d) => d[x_selected]))
.nice()
.range([0, width]);
const y = d3
.scaleLinear()
.domain(d3.extent(iris, (d) => d[y_selected]))
.nice()
.range([height, 0]);
const svg = d3
.create("svg")
.attr("width", width + marginLeft + marginRight)
.attr("height", height + marginTop + marginBottom);
const g = svg
.append("g")
.attr("transform", `translate(${marginLeft}, ${marginTop})`);
g.append("g")
.attr("transform", `translate(0,${height})`)
.call(d3.axisBottom(x).ticks(width / 80));
g.append("g").call(d3.axisLeft(y));
const Set1_Cynthia_Brewer = [
"#e41a1c",
"#377eb8",
"#4daf4a",
"#984ea3",
"#ff7f00",
"#ffff33",
"#a65628",
"#f781bf",
"#999999"
];
const colorScale = d3
.scaleOrdinal()
.domain([...new Set(iris.map((d) => d.species))])
.range(Set1_Cynthia_Brewer.slice(0, 3));
g.append("g")
.selectAll("circle")
.data(iris)
.join("circle")
.attr("cx", (d) => x(d[x_selected]))
.attr("cy", (d) => y(d[y_selected]))
.style("fill", (d) => colorScale(d.species))
.attr("r", 4);
return svg.node();
}