Simple Linear Regression + Scatterplot with D3
This example demonstrates a simple linear regression overlaid on a scatterplot, using D3 v4 with SVG rendering to visualize the relationship between years of experience and salary. The chart employs d3.scaleLinear for both axes and d3.axisBottom/axisLeft for ticks, while the regression calculations and line generation are handled by the Simple-Statistics.js library functions ss.linearRegression and ss.linearRegressionLine. The regression line connects the first and last x-coordinates of the dataset, with the title and explanatory markdown cells providing context for the analysis.
AI-generated descriptionSimple Linear Regression + Scatterplot with D3
https://observablehq.com/d/69731a80206f9b08@218
View this notebook in your browser by running a web server in this folder. For example:
python -m SimpleHTTPServer
Or, use the Observable Runtime to import this module directly into your application. To npm install:
npm install @observablehq/runtime@4
npm install https://api.observablehq.com/d/69731a80206f9b08.tgz?v=3
Then, import your notebook and the runtime as:
import {Runtime, Inspector} from "@observablehq/runtime";
import define from "69731a80206f9b08";
To log the value of the cell named “foo”:
const runtime = new Runtime();
const main = runtime.module(define);
main.value("foo").then(value => console.log(value));