{
const svg = d3.create("svg")
.attr("width",width)
.attr("height",height);
const xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x));
const yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y));
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
const colorScale = d3.scaleOrdinal()
.domain(["Setosa", "Versicolor", "Virginica"])
.range(["#ff006e", "#3a86ff", "#fb5607"]);
svg.append("g")
.selectAll("circle")
.data(datos_ejercicio_a)
.enter()
.append("circle")
.attr("cx", d => x(d[campo_x]))
.attr("cy", d => y(d[campo_y]))
.attr("r",6)
.attr("fill", d => colorScale(d.Species));
svg.append("text")
.attr("x", width / 2)
.attr("y", height - margin.bottom + 35)
.attr("text-anchor", "middle")
.style("font-size", "14px")
.style("fill", "black")
.text(campo_x);
svg.append("text")
.attr("x", -height / 2)
.attr("y", margin.left - 35)
.attr("transform", "rotate(-90)")
.attr("text-anchor", "middle")
.style("font-size", "14px")
.style("fill", "black")
.text(campo_y);
return svg.node();
}