Skip to main content
Public

Share visualization

Loading preview…

Linear Regression Line with D3.js

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

Linear Regression Line with D3.js

0
KKeerthiKandadai
Last edited May 10, 2020
Created on May 10, 2020

This example shows the correlation between a country’s happiness score and its health expenditure per person using a scatter plot with a linear regression trendline. The visualization, built with D3.js v3 and SVG, plots each country as a green circle, with axes labeled in dollars and happiness scores, and overlays a blue best-fit line computed via a least-squares function that returns the slope, intercept, and R-squared value. Data is loaded from a CSV file hosted on GitHub, while the regression calculation uses native array methods like `map` and `reduce`.

AI-generated description

A regression line visualization using D3 and vega-lite

Comments

Sign in to join the discussion.

MIT Licensed