{
const height = 300
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
let data = iris
const margin = ({top: 20, right: 30, bottom: 30, left: 40})
const h = 300 - margin.top - margin.bottom
const w = height - margin.left - margin.right
const x = d3.scaleLinear()
.domain([d3.min(data, d => d.sepal_width),
d3.max(data, d => d.sepal_width)])
.range([margin.top, h])
const y = d3.scaleLinear()
.domain([d3.min(data, d => d.sepal_length),
d3.max(data, d => d.sepal_length)])
.range([margin.left, w])
const color = d3.scaleOrdinal(d3.schemeCategory10)
svg.selectAll("#circle")
.data(data)
.enter()
.append("circle")
.attr("id", "circle")
.attr("cx", d => x(d.sepal_width))
.attr("cy", d => y(d.sepal_length))
.attr("fill", d => color(d.species))
.attr("r", 5)
svg.selectAll("rect").data(color.domain())
.enter()
.append("rect")
.attr("x", 400)
.attr("y", (d, i) => 15 + i * 30)
.attr("width", 10)
.attr("height", 10)
.attr("fill", d => color(d))
svg.selectAll("text").data(color.domain())
.enter()
.append("text")
.attr("x", 400+15)
.attr("y", (d, i) => 15 + i * 30 +10)
.text(d => d)
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);
return svg.node()
}