Public
Edited
Jul 11, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
HTL-MAR-FiddlerCrabBodySize.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
crabs

// Note there is whitespace after the variable "Site "
Insert cell
Insert cell
Insert cell
crabsJS = crabs.map(d => ({lat: d.Latitude,
site: d["Site "], // Need bracket notation
sizeMm: d.carapace_width,
airTempC: d.MATA,
waterTempC:d.MATW}))

// Use parentheses around curly braces ensures the resulting array will contain objects
// Note this is like combining select() and rename() in R
Insert cell
Insert cell
Insert cell
Insert cell
crabsJS
X
sizeMm
Y
Color
#1eb8d0
Size
Facet X
Facet Y
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
viewof pickColor = Inputs.color({label: "Pick a color!", value: "#4682b4"})
Insert cell
Plot.plot({
x: { label: "Carapace Size (mm)" },
marks: [ // Note marks are specified, not chart types
Plot.rectY(
crabsJS, // See data source
Plot.binX({ y: "count" }, { x: "sizeMm", fill: pickColor, tip: true })
),
Plot.ruleY([0])
]
})

// Note there is also a special tip mark that allow one to customize the tooltip
// See Plot also uses the grammar of graphics
// See the input cell pickColor above that that allows user to change color dynamically
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(crabsJS, {x: "lat", y: "sizeMm"})
]
})
Insert cell
Insert cell
Insert cell
ML = require("https://www.lactame.com/lib/ml/6.0.0/ml.min.js")

// Note ML.js library does not automatically exist, unlike Plot, D3, Arquero, etc.
// Give library a nickname ML for future references
Insert cell
Insert cell
crabsLM = new ML.SimpleLinearRegression(
crabsJS.map(d => d.lat),
crabsJS.map(d => d.sizeMm) // Note this is y, our independent variable
)

// Need "new" for ML model
// Use array of values for x and y as input for ML method; do with map() method
Insert cell
Insert cell
Insert cell
crabsJS
X
lat
Y
sizeMm
Color
Size
Facet X
Facet Y
Mark
dot
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
marks: [
Plot.dot(crabsJS, { x: "lat", y: "sizeMm", tip: true }),
Plot.linearRegressionY(crabsJS, {x: "lat", y: "sizeMm"}),
Plot.frame()
],
x: {label: "Latitude"},
y: {label: "Carapace Size (mm)"}
})

// Layer compatible marks on top of each other
// See simple linear regression notebook for more options
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