{
const width = 350;
const height = 350;
const margin = { top: 20, right: 20, bottom: 40, left: 50 };
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const x = d3.scaleLinear()
.domain(d3.extent(iris, d => d.longitud_sepalo))
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.domain(d3.extent(iris, d => d.longitud_petalo))
.range([height - margin.bottom, margin.top]);
const color = d3.scaleOrdinal()
.domain([...new Set(iris.map(d => d.especie))])
.range(["green", "red", "blue"]);
svg.append("g")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x))
.append("text")
.attr("x", width / 2)
.attr("y", 30)
.attr("fill", "black")
.attr("text-anchor", "middle")
.text("Longitud de Sépalo");
svg.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.append("text")
.attr("transform", "rotate(-90)")
.attr("x", -height / 2)
.attr("y", -35)
.attr("fill", "black")
.attr("text-anchor", "middle")
.text("Longitud de Pétalo");
svg.selectAll("circle")
.data(iris)
.join("circle")
.attr("cx", d => x(d.longitud_sepalo))
.attr("cy", d => y(d.longitud_petalo))
.attr("r", 4)
.attr("fill", d => color(d.especie))
.attr("opacity", 0.8);
return svg.node();
}