Public
Edited
Jul 28, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
maples = d3.csv("https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-hbr.157.3&entityid=5c415a399b00430d35d13c31312f1e53", d3.autoType)
Insert cell
Insert cell
Insert cell
Insert cell
maples
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
maples2003 = maples
.filter(d => d.Year == 2003)
.map( d=> ({
year: d.Year,
watershed: d.Watershed,
stemLength: d.StemLength,
leafMass: d.LeafDryMass,
stemMass: d.StemDryMass,
leafArea: d.CorrectedLeafArea
}))
Insert cell
Insert cell
Insert cell
Insert cell
maples2003
X
leafArea
Y
Color
Size
Facet X
Facet Y
watershed
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(maples2003, {x: "stemLength", y: "stemMass", fill: "watershed"}),
Plot.linearRegressionY(maples2003, {x: "stemLength", y: "stemMass", stroke: "watershed"}),
Plot.frame()
]
})
Insert cell
Insert cell
Insert cell
Insert cell
import {PlotMatrix} with {maples2003 as data} from "@observablehq/autoplot-matrix"
Insert cell
PlotMatrix(maples2003)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ML = require("https://www.lactame.com/lib/ml/6.0.0/ml.min.js")
Insert cell
reference = maples2003.filter(d => d.watershed == 'Reference')
Insert cell
referenceLM = new ML.SimpleLinearRegression(
reference.map(d => d.stemLength),
reference.map(d => d.stemMass)
)
Insert cell
W1 = maples2003.filter(d => d.watershed == 'W1')
Insert cell
W1LM = new ML.SimpleLinearRegression(
W1.map(d => d.stemLength),
W1.map(d => d.stemMass)
)
Insert cell
Insert cell
import {scale, asMatrix} from "@chrispahm/hierarchical-clustering"
Insert cell
maplesScaled = scale(maples2003.map(({ year, watershed, ...rest}) => rest))
Insert cell
maplesArray = maplesScaled.map(Object.values)
Insert cell
maplesClusters = ML.KMeans(maplesArray, 2)
Insert cell
maplesKmeans = maples2003.map((d,i) => ({...d, clusterNo: maplesClusters.clusters[i]}))
Insert cell
clusterchart = Plot.plot({ // Remember to name if you want to use embeds!
marks: [
Plot.text(maplesKmeans, {
x: "stemLength",
y: "stemMass",
text: "clusterNo",
fontSize: "15px",
fontWeight: 500,
fill: "watershed",
tip: true
})
],
color: { legend: true }
})
Insert cell
Insert cell
maplesPCA = new ML.PCA(maplesArray)
Insert cell
maplesPCA.getExplainedVariance()
Insert cell
maplesPCA.getCumulativeVariance()
Insert cell
import { viewof loadings } with { maplesScaled as food_scaled } from "@chrispahm/principal-component-analysis"
Insert cell
viewof loadings
Insert cell
import { viewof scores } with { maplesArray as food_scaled, maples2003 as food} from "@chrispahm/principal-component-analysis"
Insert cell
viewof scores
Insert cell
// Do some wrangling to get the month and season alongside scores:
scoresCombined = scores.map((d, i) => ({
...d,
year: maples2003[i].year,
watershed: maples2003[i].watershed
}))
Insert cell
scalingFactor = 4
Insert cell
pcachart = Plot.plot({
marks: [
Plot.dot(scoresCombined, { x: "PC1", y: "PC2", fill: "watershed", r: 5 }),
Plot.arrow(loadings, {
x1: 0, x2: d => d.PC1 * scalingFactor, y1: 0, y2: (d) => d.PC2 * scalingFactor
}),
Plot.text(loadings, {
x: (d) => d.PC1 * scalingFactor, y: (d) => d.PC2 * scalingFactor,
text: "Variable",
dy: -5,
dx: 30,
fill: "black",
stroke: "white"
})
],
color: { legend: true }
})
Insert cell
Insert cell
Insert cell
Insert cell
Calcium addition appears to increase the overall dimensions and mass of stems and leaves in the seedlings in the treated watershed compared to untreated watershed.
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