Published
Edited
Jun 15, 2021
3 forks
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
data = d3.csv(
"https://raw.githubusercontent.com/allisonhorst/palmerpenguins/master/inst/extdata/penguins.csv",
d3.autoType // this will automatically convert the CSV text into numbers and dates as appropriate
) // d3.csv() returns a JavaScript Promise, which the notebook cell displays when it resolves
Insert cell
Inputs.table(data)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
myScale = d3.scaleLinear()
.domain([0, 10000]) // the domain is the "input", based on the data
.range([100, 700]) // the range is the "output", usually pixels or some visual property
Insert cell
Insert cell
viewof value = Inputs.range([0, 10000], { step: 100 })
Insert cell
Insert cell
myScale(value) // as you change the slider, this value will change too
Insert cell
Insert cell
Insert cell
d3.min(data, d => d.flipper_length_mm)
Insert cell
d3.max(data, d => d.flipper_length_mm)
Insert cell
d3.extent(data, d => d.flipper_length_mm)
Insert cell
Insert cell
// Type your code here
xScale = d3.scaleLinear()

Insert cell
Insert cell
Insert cell
// this should change once you've set the domain and range of your scale
xScale(data[0].bill_length_mm)
Insert cell
Insert cell
Insert cell
yScale = d3.scaleLinear()
.domain(d3.extent(data, d => d.bill_depth_mm))
.range([20, 380])
Insert cell
Insert cell
{
let svg = d3.create("svg")
.attr("width", 640)
.attr("height", 400)

svg.selectAll("circle")
.data([1,2,3])
.join("circle")
.attr("cx", d => 100 + d * 150)
.attr("cy", 200)
.attr("r", 50)
return svg.node()
}
Insert cell
Insert cell
// Type your code here


Insert cell
Insert cell
Insert cell
species = _.uniqBy(data, d => d.species).map(d => d.species)
Insert cell
colorScale = d3.scaleOrdinal()
.domain(species)
// let's use the 3 colors from the Palmer project graphics
.range([
"rgb(185,100,198)",
"rgb(47,110,116)",
"rgb(240,137,51)"
])
Insert cell
Insert cell
swatches({ color: colorScale })
Insert cell
Insert cell
// Type your code here


Insert cell
Insert cell
Insert cell
{
let svg = d3.create("svg").attr("width", width).attr("height", 40)
let g = svg.append("g").attr("transform", "translate(20,0)")

let xAxis = d3.axisBottom(xScale) // this sets up the axis component
//.ticks(5) // you can customize it by chaining options here
xAxis(g) // this renders SVG elements into the "g" container
return svg.node()
}
Insert cell
Insert cell
// Type your code here


Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more