Public
Edited
Jul 6
Insert cell
Insert cell
irisData = d3.csv("https://gist.githubusercontent.com/007blesson/38787b3829019d5b99cd9b7f9b6e44ba/raw/c0ba2e231e929a83f11dfcd551ed4d571b40c3a4/iris_data.csv", d3.autoType)

Insert cell
{
const width = 600;
const height = 400;
const margin = {top: 20, right: 20, bottom: 40, left: 40};
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const x = d3.scaleLinear()
.domain(d3.extent(irisData, d => d["sepal_width"]))
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.domain(d3.extent(irisData, d => d["sepal_length"]))
.range([height - margin.bottom, margin.top]);
const color = d3.scaleOrdinal()
.domain(["setosa", "versicolor", "virginica"])
.range(["lightblue", "lightgreen", "orange"]);
svg.append("g")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(6));
svg.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(6));
svg.append("g")
.selectAll("circle")
.data(irisData)
.join("circle")
.attr("cx", d => x(d["sepal_width"]))
.attr("cy", d => y(d["sepal_length"]))
.attr("r", 5)
.attr("fill", d => color(d.species));
svg.append("text")
.attr("x", width / 2)
.attr("y", 15)
.attr("text-anchor", "middle")
.text("Reusable Scatter Plot - Sepal Width vs Sepal Length");
return svg.node();
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more