{
const margin = { top: 20, right: 20, bottom: 50, left: 50 };
const width = 350;
const height = 350;
const innerWidth = width - margin.left - margin.right;
const innerHeight = height - margin.top - margin.bottom;
const x = d3.scaleLinear()
.domain(d3.extent(datosFiltrados, d => +d[variableX]))
.range([0, innerWidth]);
const y = d3.scaleLinear()
.domain(d3.extent(datosFiltrados, d => +d[variableY]))
.range([innerHeight, 0]);
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const g = svg.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
g.append("rect")
.attr("width", innerWidth)
.attr("height", innerHeight)
.attr("fill", "white");
g.selectAll("circle")
.data(datosFiltrados)
.join("circle")
.attr("cx", d => x(+d[variableX]))
.attr("cy", d => y(+d[variableY]))
.attr("r", 4)
.attr("fill", "steelblue")
.attr("opacity", 0.7);
g.append("g")
.attr("transform", `translate(0,${innerHeight})`)
.call(d3.axisBottom(x));
g.append("g")
.call(d3.axisLeft(y));
g.append("text")
.attr("x", innerWidth / 2)
.attr("y", innerHeight + 40)
.attr("text-anchor", "middle")
.attr("fill", "black")
.text(variableX);
g.append("text")
.attr("transform", "rotate(-90)")
.attr("x", -innerHeight / 2)
.attr("y", -35)
.attr("text-anchor", "middle")
.attr("fill", "black")
.text(variableY);
return svg.node();
}