viewof scatterplot_area = {
const margin = { top: 20, right: 20, bottom: 40, left: 50 };
const width = 350;
const height = 350;
const innerWidth = width - margin.left - margin.right;
const innerHeight = height - margin.top - margin.bottom;
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const data = await d3.csv("https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/iris.csv", d => {
const petalLength = +d.Petal_Length;
const petalWidth = +d.Petal_Width;
return {
longitud_sepalo: +d.Sepal_Length,
longitud_petalo: petalLength,
especie: d.Species,
area_petalo: (petalLength * petalWidth) / 2
};
});
const x = d3.scaleLinear()
.domain(d3.extent(data, d => d.longitud_sepalo))
.range([0, innerWidth]);
const y = d3.scaleLinear()
.domain(d3.extent(data, d => d.longitud_petalo))
.range([innerHeight, 0]);
const color = d3.scaleSequential()
.domain(d3.extent(data, d => d.area_petalo))
.interpolator(d3.interpolatePlasma);
const r = d3.scaleSqrt()
.domain(d3.extent(data, d => d.area_petalo))
.range([2, 10]);
const g = svg.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
g.append("g")
.attr("transform", `translate(0,${innerHeight})`)
.call(d3.axisBottom(x));
g.append("g")
.call(d3.axisLeft(y));
g.selectAll("circle")
.data(data)
.join("circle")
.attr("cx", d => x(d.longitud_sepalo))
.attr("cy", d => y(d.longitud_petalo))
.attr("r", d => r(d.area_petalo))
.attr("fill", d => color(d.area_petalo))
.attr("opacity", 0.7);
return svg.node();
}