{
const height = 700
const padding=150
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
let data = raw
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([0,
d3.max(data, d => d.sepal_width)])
.range([padding, width-padding])
const y = d3.scaleLinear()
.domain([0,
d3.max(data, d => d.sepal_length)])
.range([height-padding, padding])
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("opacity", 0)
.attr("r", 5)
svg.selectAll("rect").data(color.domain())
.enter()
.append("rect")
.attr("x", width-padding+30)
.attr("y", (d, i) => 100 + i * 20)
.attr("width", 10)
.attr("height", 10)
.attr("fill", d => color(d))
const shape = d3.scaleOrdinal()
.domain(raw.map(d => d.species))
.range(d3.symbols.map(s => d3.symbol().type(s)()))
const marks = svg.selectAll(".marks")
.data(data)
.enter().append("path")
.attr("class", "marks")
.attr("transform", d => `translate(${x(d["sepal_width"])}, ${y(d["sepal_length"])})`)
.attr("fill", d => color(d["species"]))
.attr("d", d => shape(d["species"]));
console.log(shape("setosa"))
svg.selectAll("text").data(color.domain())
.enter()
.append("text")
.attr("x", width-padding+30+20)
.attr("y", (d, i) => i*20+100+10)
.text(d => d)
const xAxis=d3.axisBottom(x)
const yAxis=d3.axisLeft(y)
svg.append("g")
.attr("transform","translate(0," + (height-padding) + ")")
.call(xAxis)
svg.append("g")
.attr("transform","translate(" + padding + ",0)")
.call(yAxis)
return svg.node()
}