scatterplot = (var_x, var_y) => {
const margin = ({top: 20, right: 30, bottom: 30, left: 40})
const width = 400
const height = 300
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
const x = d3.scaleLinear()
.domain([d3.min(raw_dataset, d => d[var_x]),
d3.max(raw_dataset, d => d[var_x])])
.range([margin.left, width -margin.left-margin.right])
const y = d3.scaleLinear()
.domain([d3.min(raw_dataset, d => d[var_y]),
d3.max(raw_dataset, d => d[var_y])])
.range([margin.top, height -margin.top-margin.bottom])
const c = d3.scaleOrdinal().domain(species).range(d3.schemeCategory10)
svg.selectAll("circle").data(raw_dataset).enter().append("circle")
.attr("cx", d => x(d[var_x]))
.attr("cy", d => y(d[var_y]))
.attr("r", d => d[var_y])
.attr("fill", d => c(d["species"]))
const xAxis = g => g.append('g')
.attr('transform', `translate(0, ${height-margin.bottom-margin.top})`)
.call(d3.axisBottom(x))
const yAxis = g => g.append('g')
.attr('transform', `translate(${margin.left}, 0)`)
.call(d3.axisLeft(y))
svg
.call(xAxis)
.call(yAxis)
var legend = svg.selectAll(".legend")
.data(c.domain())
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
legend.append("rect")
.attr("width", 10)
.attr("height", 10)
.style("fill", function(d) { return c(d); })
.attr("transform", function(d, i) {
return "translate(" + (width -10) + "," + 10 + ")";
})
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.attr("font-size", 15)
.style("text-anchor", "end")
.text(function(d) { return d; });
return svg.node()
}