{
const margin = ({top: 20, right: 30, bottom: 30, left: 40})
const w = 300
const h = 300
const svg = d3.create("svg").attr("width", w).attr("height", h);
const data = penguins
const titre = svg.append("text").attr("x", 100).attr("y", 20).text("MON TITRE")
const scaleY = d3.scaleLinear().domain([0, d3.max(penguins, d => d.culmen_length_mm)
]).range([300, 0]);
const scaleX = d3.scaleLinear().domain([0, d3.max(penguins, d => d.culmen_depth_mm)
]).range([0, 300]);
const color = d3.scaleOrdinal(d3.schemeCategory10)
svg.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr("cx", (d, i) => scaleX(d.culmen_depth_mm))
.attr("cy", (d, i) => scaleY(d.culmen_length_mm))
.style("fill", d => color(d.sex))
.attr("r", 3)
const legend = svg.selectAll("rect")
.data(list_categories)
.enter()
legend.append("rect")
.attr("x", 50)
.attr("y", (d,i) => 50 + i*20)
.attr("height", 10)
.attr("width", 10)
.style("fill", d => color(d))
legend.append("text")
.attr("x", 70)
.attr("y", (d,i) => 50 + i*20)
.text(d => d)
const xAxis = g => g
.attr("transform", `translate(0, ${280})`)
.call(d3.axisBottom(scaleX))
const yAxis = g => g
.attr("transform", `translate(${20}, 0)`)
.call(d3.axisLeft(scaleY))
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
return svg.node()
}