graficoDispersiónConTexto = {
const width = 800;
const height = 500;
const margin = { top: 40, right: 30, bottom: 70, left: 70 };
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const g = svg.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
const x = d3.scaleLinear()
.domain(d3.extent(datosMigrantes, d => +d["Incident Year"]))
.range([0, width - margin.left - margin.right]);
const y = d3.scaleLinear()
.domain([0, d3.max(datosMigrantes, d => +d["Total Number of Dead and Missing"])])
.nice()
.range([height - margin.top - margin.bottom, 0]);
const color = d3.scaleOrdinal(d3.schemeCategory10);
const radius = d3.scaleSqrt()
.domain([0, d3.max(datosMigrantes, d => +d["Number of Children"])])
.range([2, 20]);
const puntos = datosMigrantes.filter(d =>
d["Incident Year"] &&
d["Total Number of Dead and Missing"] > 100 &&
d["Number of Children"] > 0
).slice(0, 50);
g.append("g")
.attr("transform", `translate(0, ${height - margin.top - margin.bottom})`)
.call(d3.axisBottom(x).tickFormat(d3.format("d")));
g.append("g")
.call(d3.axisLeft(y));
g.selectAll("circle")
.data(puntos)
.join("circle")
.attr("cx", d => x(+d["Incident Year"]))
.attr("cy", d => y(+d["Total Number of Dead and Missing"]))
.attr("r", d => radius(+d["Number of Children"]))
.attr("fill", d => color(d["Region of Incident"]))
.attr("opacity", 0.6);
g.selectAll("text")
.data(puntos)
.join("text")
.attr("x", d => x(+d["Incident Year"]))
.attr("y", d => y(+d["Total Number of Dead and Missing"]) - 5)
.text(d => d["Region of Incident"])
.attr("font-size", "10px")
.attr("text-anchor", "middle")
.attr("fill", "#333");
return svg.node();
}