Klar

Charts / React science and statistics charts / Relationship

Hexbin density

Thousands of points binned into hexagons on a sequential ramp with density contours, for scatter that is too dense to read point by point.

React component HexbinDensity, data through props. How variables move together: correlation, density and many dimensions at once. Tags: hexbin, density, scatter, binning, contours, large-data.

Install

npm i klar-charts

import 'klar-charts/styles.css'
import { ThemeScope, HexbinDensity } from 'klar-charts'

# or copy the source:
npx shadcn@latest add https://klar.run/r/sci-hexbin.json

Usage

<HexbinDensity
  points={cmdStars}
  height={420}
  radius={6}
  xDomain={[-0.5, 3.6]}
  yDomain={[-2, 16]}
  invertY
  scale={scale}
  xLabel="Colour BP − RP (mag)"
  yLabel="Absolute magnitude, G band (mag)"
  xName="BP − RP"
  yName="Abs. magnitude G"
  countLabel="Stars per bin"
  labels={[
    { x: 2.2, y: 8.1, text: 'Main sequence', anchor: 'start' },
    { x: 1.02, y: 0.55, text: 'Red clump', anchor: 'end' },
    { x: 1.62, y: 1.9, text: 'Giant branch', anchor: 'start' },
    { x: 0.15, y: 14.6, text: 'White dwarfs', anchor: 'middle' },
  ]}
/>

Related hexbin density charts