> ## Documentation Index
> Fetch the complete documentation index at: https://docs.graphy.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Scatter & bubble

export const GraphEmbed = ({src, story, aspectRatio, borderRadius = '14px', args}) => {
  const STORYBOOK_BASE_URL = window.location.hostname === 'localhost' ? 'http://localhost:6006' : 'https://storybook-sdk.vercel.app';
  function buildArgsString(args) {
    if (!args) return '';
    const encodeValue = value => {
      if (value === null) return '!null';
      if (value === undefined) return '!undefined';
      if (typeof value === 'boolean') return `!${value}`;
      if (typeof value === 'number') return String(value);
      return encodeURIComponent(String(value));
    };
    const properties = Object.entries(args).map(([key, value]) => `${key}:${encodeValue(value)}`).join(';');
    return `&args=${properties}`;
  }
  const resolvedSrc = story ? `${STORYBOOK_BASE_URL}/iframe.html?id=${story}&viewMode=story&embed=1${buildArgsString(args)}` : src;
  const resolvedAspectRatio = aspectRatio ?? (story ? '16 / 9' : '10 / 6');
  return <iframe src={resolvedSrc} loading="lazy" allowfullscreen="true" style={{
    width: '100%',
    aspectRatio: resolvedAspectRatio,
    border: 'none',
    borderRadius,
    colorScheme: 'light'
  }} />;
};

A scatter plot draws a `geom.point()` per observation against two continuous axes — the tool for correlation and distribution. Add a `size` mapping and it becomes a bubble chart, encoding a third variable.

## Scatter

Map two numeric columns to `x` and `y`, and declare continuous scales:

<GraphEmbed story="chart-types-point-graph--simple" />

```tsx theme={null}
import { useMemo } from 'react';
import { createSpec, pipe, geom, scale } from '@graphysdk/viz-engine';
import { GraphProvider, GraphRenderer } from '@graphysdk/react-renderer';

const data = {
  columns: [
    { key: 'weight', label: 'Weight' },
    { key: 'height', label: 'Height' },
  ],
  rows: [
    { weight: 60, height: 160 },
    { weight: 65, height: 165 },
    { weight: 70, height: 175 },
    { weight: 75, height: 170 },
    { weight: 80, height: 180 },
    { weight: 85, height: 178 },
    { weight: 90, height: 185 },
  ],
};

export function WeightVsHeight() {
  const spec = useMemo(
    () =>
      pipe(
        createSpec({ x: 'weight', y: 'height' }),
        geom.point(),
        scale.x.continuous(),
        scale.y.continuous()
      ),
    []
  );

  return (
    <GraphProvider input={spec} data={data}>
      <GraphRenderer />
    </GraphProvider>
  );
}
```

## Coloring by category

Map a category to `color` to distinguish groups of points:

<GraphEmbed story="chart-types-point-graph--color-grouped" />

```tsx theme={null}
const spec = pipe(
  createSpec({ x: 'weight', y: 'height', color: 'gender' }),
  geom.point(),
  scale.x.continuous(),
  scale.y.continuous(),
  scale.color.palette()
);
```

## Bubble

Map a third numeric column to `size` and add a size scale. The default size scale uses a square-root transform, so bubble **area** is proportional to the value:

<GraphEmbed story="chart-types-point-graph--size-and-color" />

```tsx theme={null}
const spec = pipe(
  createSpec({
    x: 'gdp',
    y: 'lifeExpectancy',
    size: 'population',
    color: 'continent',
  }),
  geom.point(),
  scale.x.continuous(),
  scale.y.continuous(),
  scale.size.continuous()
);
```

## Related

* [Scales](/sdk-next/concepts/scales) — continuous and size scales
* [Statistics](/sdk-next/advanced/statistics) — add a `smooth` trendline over the points
