Published
Edited
Oct 29, 2020
1 fork
Insert cell
Insert cell
Insert cell
gapminder = d3.json("https://vega.github.io/vega-datasets/data/gapminder.json")
Insert cell
Insert cell
fertilityScale = d3.scaleLinear()
.domain([0,d3.max(desiredData, d => d.fertility)])
.range([margin, width - margin]);
Insert cell
lifeExpectScale = d3.scaleLinear()
.domain([0,d3.max(desiredData, d => d.life_expect)])
.range([height - margin, margin]);
Insert cell
lifeExpectScale(d3.max(desiredData, d => d.life_expect))
Insert cell
populationScale = d3.scaleSqrt()
.domain([0,d3.max(desiredData, d => d.pop)])
.range([0, 40]);
Insert cell
viewof parameters = form(html`<form>
<div>
<i>year: </i><label><input name="year" type=range min="1955" max="2005" value="1970" step="5" oninput="this.nextElementSibling.value = this.value">
<output>1970</output> </label>
</div>
</div>
</form>`)
Insert cell
scatterplot = {
const svg = d3.select(DOM.svg(width, height));
svg.selectAll('circle')
.data(desiredData)
.join('circle')
.attr('cx', d => fertilityScale(d.fertility))
.attr('cy', d => lifeExpectScale(d.life_expect))
.attr('r', d => populationScale(d.pop))
.attr('fill', d => d3.schemeCategory10[d.cluster])
.attr('fill-opacity', 0.4)
.attr('stroke', d => d3.schemeCategory10[d.cluster])

// Specific to Observable
return svg.node();
}
Insert cell
Insert cell
d3.schemeCategory10
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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