---
title: Custom Graph リファレンス
description: Custom Graph で利用可能な Geometry（形状）と Statistics（統計変換）の一覧です。
priority: 0.5
---

# Custom Graph リファレンス {#custom-graph-reference}

[Custom Graph](custom-graph) で利用可能な Geometry と Statistics の一覧です。各項目の詳細は、レイヤー設定内のヘルプボタン（?）で確認できます。

テーブル内の Description はアプリ UI の表記と一致させるため英語で記載しています。

## Geometry（形状） {#geometry}

<!-- AUTO_GENERATED:GEOM_TABLE -->
| Geometry | Description |
|----------|-------------|
| Point (Scatter) | Displays data as individual points. |
| Line | Connects data points with lines. Draws an interval band automatically when ymin/ymax are present. |
| Bar | Vertical bars for categorical data. Use Fill (not Color) to change bar color. |
| Area | Filled area under line. |
| Tile (Heatmap) | Grid of colored cells. Use Fill to set cell colors. |
| Step (Kaplan-Meier) | Stair-step line pattern. Used for Kaplan-Meier curves and ECDF. |
| Ribbon (Confidence Band) | Shaded area between ymin and ymax (confidence bands). |
| Error Bar | Error bars showing ymin to ymax range with caps. |
| Vertical Line (Reference) | Fixed vertical reference line. Configure style in the layer settings. |
| Horizontal Line (Reference) | Fixed horizontal reference line. Configure style in the layer settings. |
| Contour | Draws a curve from a series of points. Used for Cook's distance contours in regression diagnostics. |
| Density 2D | 2D kernel density estimation as contour lines. For 1D density curves, use the Density (KDE) statistic. |
| Text (Label) | Displays text labels at data points. Requires the Label aesthetic. |
| Label (Annotation) | Displays text boxes with leader lines at data points. Includes automatic collision avoidance. |
<!-- /AUTO_GENERATED:GEOM_TABLE -->

### Geometry と aesthetic の互換性 {#geom-aes}

各 Geometry は特定の [aesthetic](custom-graph#aesthetics---mapping-visual-elements)（位置・色・サイズなどの視覚マッピング）のみを受け付けます。対応していない aesthetic を指定しても効果はありません。

| Geometry | x | y | color | fill | stroke | size | shape | alpha | linetype | ymin | ymax | label |
|----------|:-:|:-:|:-----:|:----:|:------:|:----:|:-----:|:-----:|:--------:|:----:|:----:|:-----:|
| point    | **R** | **R** | • |   | • | • | • | • |   |   |   |   |
| line     | **R** | **R** | • |   |   | • |   | • | • | ○ | ○ |   |
| bar      | **R** | **R** |   | • |   |   |   | • |   |   |   |   |
| area     | **R** | **R** | • | • |   |   |   | • |   |   |   |   |
| tile     | **R** | **R** |   | • |   |   |   | • |   |   |   |   |
| step     | **R** | **R** | • |   |   | • |   | • | • |   |   |   |
| ribbon   | **R** |       | • | • |   |   |   | • |   | **R** | **R** |   |
| errorbar | **R** |       | • |   |   |   |   | • |   | **R** | **R** |   |
| vline    | • |       | • |   |   |   |   |   |   |   |   |   |
| hline    |   | •     | • |   |   |   |   |   |   |   |   |   |
| contour  | **R** | **R** | • |   |   |   |   | • |   |   |   |   |
| density2d| **R** | **R** |   |   |   |   |   | • |   |   |   |   |
| text     | **R** | **R** | • |   |   | • |   | • |   |   |   | • |
| label    | **R** | **R** | • |   |   |   |   | • |   |   |   | • |

**R** = required（必須）, ○ = optional（指定時に追加の動作が発生）, • = supported（対応）

- **Required** の aesthetic はカラムへのマッピングか Statistics による供給が必要です。
- **color** と **fill** の違い: Bar と Tile は塗りつぶしに `fill` を使います（`color` ではありません）。Area は両方を受け付けます — `color` は輪郭線、`fill` は塗りつぶしです。Ribbon は輪郭線を描画せず、`color` が塗りつぶし色を決めます。Ribbon の `fill` は threshold カラースケールを使う場合にのみ参照されます。
- **stroke**: Point のみが対応しています。ポイントの輪郭色を設定します。
- **ymin / ymax**: Line は両方が存在するとインターバルバンドを描画します。Ribbon と Errorbar では必須です。

## Statistics（統計変換） {#statistics}

<!-- AUTO_GENERATED:STAT_TABLE -->
| Statistics | Description |
|------------|-------------|
| Identity (No transformation) | Passes data through without transformation. |
| Bin (Histogram) | Groups numeric data into bins and counts occurrences. |
| Time Bin (Datetime Histogram) | Groups datetime data into time intervals. |
| Smooth (Regression) | Fits a smoothing curve with linear regression or LOESS. Optionally computes ymin/ymax as either a prediction interval for a new individual observation or a confidence interval for the mean response; Line geom draws the band automatically, Ribbon geom can also be used. |
| Count (Aggregation) | Counts occurrences for each X value. |
| Density (KDE) | Estimates probability density using kernel density estimation. |
| Summary (Aggregation) | Aggregates Y values by X using mean, sum, median, min, max, standard deviation, or variance. |
| Survival (Kaplan-Meier) | Computes Kaplan-Meier survival estimates. |
| X Mean | Calculates the mean of X values. Use with vline geom to draw a vertical reference line. |
| X Median | Calculates the median of X values. Use with vline geom to draw a vertical reference line. |
| Y Mean | Calculates the mean of Y values. Use with hline geom to draw a horizontal reference line. |
| Cumulative Sum (Pareto) | Computes cumulative sum of Y values. Combine with Sort and Bar + Line to create Pareto charts. |
| Sort (Pareto) | Sorts data by Y values in descending order. Combine with Cumulative Sum to create Pareto charts. |
| ECDF (Empirical CDF) | Computes empirical cumulative distribution function. |
| QQ (Normal Q-Q Plot) | Computes quantiles for a normal Q-Q plot, using Hazen plotting positions ((i + 0.5) / n) for the theoretical quantiles. |
| Transform (Linear) | Applies linear transformation (multiply and add) to Y values. |
<!-- /AUTO_GENERATED:STAT_TABLE -->

## Statistics のパラメータ {#stat-params}

各 Statistic は [`tabs.addGraphLayer` / `tabs.updateGraphLayer`](agent-api#tabsaddgraphlayertabid-layer) の `stats` 配列に `params` オブジェクトを渡します。以下の表は各 Statistic のパラメータ名、TypeScript 型、デフォルト値、説明の一覧です。

```javascript
await window.midas.tabs.addGraphLayer('tab_001', {
  geom: { type: 'point' },
  stats: [
    { type: 'smooth', params: { method: 'loess', span: 0.5, interval: 'confidence' } }
  ],
  aes: { x: 'weight', y: 'mpg' }
});
```

型の記法: `A | B` は A か B のどちらかを指定、`T[]` は `T` の配列、フィールド名末尾の `?`（例: `p?`）は省略可能を表します。各 Statistic の前提・限界・ユースケースの詳細は [Custom Graph](custom-graph) を参照してください。

<!-- AUTO_GENERATED:STAT_PARAMS -->
### Identity (No transformation) {#stat-params-identity}

No parameters.

### Bin (Histogram) {#stat-params-bin}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `bins` | `number` | `30` | Number of bins (5-100). Ignored when binwidth is specified. |
| `binwidth` | `number` | — | Width of each bin in X-axis units. Takes precedence over bins. |
| `yScale` | `'count' \| 'density'` | `'count'` | Y-axis scale: 'count' reports bin counts, 'density' reports probability density (bin counts divided by the number of non-missing observations × binwidth, so the total area over equal-width bins equals 1). |
| `boundary` | `number` | — | Position of a bin edge in X-axis units. Bins are aligned so that one edge falls on this value. |
| `center` | `number` | — | Position of a bin center in X-axis units. Takes precedence over boundary. |

### Time Bin (Datetime Histogram) {#stat-params-timebin}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `interval` | `'auto' \| '1min' \| '5min' \| '15min' \| '30min' \| '1hour' \| '6hour' \| '12hour' \| '1day' \| '1week' \| '1month' \| '3month' \| '1year'` | `'auto'` | Time interval for bins. 'auto' chooses based on data range. |
| `yScale` | `'count' \| 'density'` | `'count'` | Y-axis scale: 'count' reports bin counts, 'density' reports probability density. |

### Smooth (Regression) {#stat-params-smooth}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `method` | `'lm' \| 'loess'` | `'loess'` | Smoothing method: 'lm' for ordinary least squares, 'loess' for locally weighted regression (tricube kernel, local linear). When a grouping aesthetic (color, fill, etc.) is mapped, a separate curve is fit per group. |
| `se` | `boolean` | `true` | When true, emits ymin/ymax for an interval band (Line geom draws the band automatically). The name follows ggplot2's se argument, but the emitted values are the interval endpoints (ymin/ymax), not a standard error. |
| `span` | `number` | `0.75` | LOESS span: fraction of points in each local neighborhood (0.1-1.0). Larger values produce smoother curves. Ignored when method is lm. |
| `level` | `number` | `0.95` | Interval level (0-1). For example, 0.95 for a 95% interval. |
| `interval` | `'confidence' \| 'prediction'` | `'prediction'` | Interval type. 'prediction' (the default) is for a new individual observation (wider, includes residual variance); 'confidence' is for the mean response (narrower). See Custom Graph for assumptions and limits. |

### Count (Aggregation) {#stat-params-count}

No parameters.

### Density (KDE) {#stat-params-density}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `bandwidth` | `number` | — | Kernel bandwidth in X-axis units. When omitted, bandwidth is selected automatically by Silverman's rule of thumb (0.9 × min(SD, IQR/1.34) × n^(-1/5)), which assumes a roughly normal shape and can oversmooth multimodal data. |
| `kernel` | `'gaussian'` | `'gaussian'` | Kernel function. Only Gaussian is supported. |
| `yScale` | `'density' \| 'count'` | `'density'` | Y-axis scale: 'density' reports probability density (total area equals 1). 'count' scales density by n × binwidth, where binwidth is computed internally (via Sturges) and may not match a co-plotted Bin layer's Y scale exactly; to overlay a histogram and a density curve on a common scale, set both layers to 'density'. |

### Summary (Aggregation) {#stat-params-summary}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `outputs` | `SummaryOutputDef[]` | `[{ fun: 'mean', to: 'y' }]` | Output definitions. Each entry is { fun, to, p?, k? }. fun selects the aggregation: 'mean', 'sum', 'median', 'min', 'max', 'sd' (sample SD, n-1 denominator), 'var' (sample variance), 'lower_se' (mean - SE, where SE = SD / sqrt(n)), 'upper_se' (mean + SE), 'lower_sd' (mean - SD), 'upper_sd' (mean + SD), 'quantile' (p-quantile with linear interpolation), 'mean_plus_k_sd' (mean + k * SD), 'mean_minus_k_sd' (mean - k * SD). to is the target position aesthetic ('y', 'ymin', or 'ymax'). p (0-1) is required for 'quantile'. k (default 1) is the SD multiplier for 'mean_plus_k_sd' / 'mean_minus_k_sd'. |
| `complete` | `boolean` | `false` | When true, fills missing X × Y combinations with 0 before aggregation. Intended for count-like aggregations; with 'mean' or 'median' the zero-fill biases the result. |

### Survival (Kaplan-Meier) {#stat-params-survival}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `confLevel` | `number` | `0.95` | Confidence level (0-1) for the pointwise confidence interval of S(t): each interval holds at a single time point and is not a simultaneous band covering the whole curve. Variance is estimated with Greenwood's formula and the interval is constructed on the log scale (so the bounds stay inside [0, 1]). |

### X Mean {#stat-params-xmean}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `label` | `string` | `'Mean: {value}'` | Label template for the reference line. {value} is replaced with the computed mean. |

### X Median {#stat-params-xmedian}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `label` | `string` | `'Median: {value}'` | Label template for the reference line. {value} is replaced with the computed median. |

### Y Mean {#stat-params-ymean}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `offset` | `number` | `0` | Number of sample SDs added to the mean; not a raw offset on the Y-axis. SD is the sample standard deviation (n-1) of the plotted Y values (computed per group when a grouping aesthetic is mapped), not a within-subgroup SD. For example, 3 draws a line at mean + 3 × SD (upper control limit, UCL), and -3 at mean − 3 × SD (lower control limit, LCL). |
| `label` | `string` | `'Mean: {value}'` | Label template for the reference line. {value} is replaced with the computed value. |

### Cumulative Sum (Pareto) {#stat-params-cumsum}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `normalize` | `boolean` | `false` | When true, scales the cumulative sum so the total equals 100 (percent). |

### Sort (Pareto) {#stat-params-sort}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `order` | `'ascending' \| 'descending'` | `'descending'` | Sort direction applied to Y values. |
| `limit` | `number` | — | Keep only the top N categories after sorting. Omit to keep all categories. |
| `displayOrder` | `'alphabetical'` | — | Controls the display order of the kept categories. Only 'alphabetical' is supported; omit to keep the sort order selected by 'order'. |

### ECDF (Empirical CDF) {#stat-params-ecdf}

No parameters.

### QQ (Normal Q-Q Plot) {#stat-params-qq}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `showReferenceLine` | `boolean` | `true` | When true, draws a reference line to assess deviation from normality. |
| `referenceLineType` | `'q1q3' \| 'identity'` | `'q1q3'` | Reference line type. 'q1q3' passes through the first and third quartiles, taken as order statistics without interpolation (so they can differ from the interpolated 'quantile' summary); use it for raw data on its original scale. 'identity' is y = x; use it only when the input is already standardized (e.g., z-scores centered at 0 and scaled by SD). |

### Transform (Linear) {#stat-params-transform}

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `multiply` | `number` | `1` | Multiplier applied to Y. For example, -1 flips a histogram for a population pyramid. |
| `add` | `number` | `0` | Offset added after multiplication. |
<!-- /AUTO_GENERATED:STAT_PARAMS -->

## Palettes（パレット） {#palettes}

`layers[].scales` の `color` / `fill` チャネルで `paletteId` に指定できる値の一覧です。API での設定方法は [Agent API](agent-api#tabsconfiguregraphtabid-config) を参照してください。

### Categorical {#palettes-categorical}

カテゴリカル変数の色分けに使います。`scaleType: 'categorical'` で指定します。

| ID | Name | Colors |
|---|---|---|
| `midas-default` | MIDAS Default | 12 |
| `tableau10` | Tableau 10 | 10 |
| `d3-category10` | D3 Category10 | 10 |

デフォルトは `midas-default` です。

### Sequential {#palettes-sequential}

連続変数や順序尺度の変数に使います。`scaleType: 'sequential'` で指定します。

`scaleType: 'categorical'` と `'threshold'` でも使用できます。カテゴリ数または閾値で区切られた領域数ぶんの色をパレット全域から等間隔にサンプリングします。

| ID | Name | Colors |
|---|---|---|
| `blues` | Blues | 9 |
| `greens` | Greens | 9 |
| `greys` | Greys | 9 |
| `purples` | Purples | 9 |
| `ylorrd` | Yellow-Orange-Red | 9 |
| `viridis` | Viridis | 10 |
| `plasma` | Plasma | 10 |
| `inferno` | Inferno | 10 |
| `magma` | Magma | 10 |

デフォルトは `blues` です。Viridis、Plasma、Inferno、Magma は知覚的に均一で色覚多様性に配慮したパレットです。

### Diverging {#palettes-diverging}

中心値からの乖離を両方向に表す変数に使います。`scaleType: 'diverging'` で指定します。

`scaleType: 'threshold'` でも使用できます。閾値で区切られた領域数ぶんの色をパレット全域から等間隔にサンプリングします。

| ID | Name | Colors |
|---|---|---|
| `rdbu` | Red-Blue | 11 |
| `brbg` | Brown-Teal | 11 |

デフォルトは `rdbu` です。

### scaleType と paletteId の互換性 {#palette-compatibility}

| scaleType | 使用可能な paletteId |
|---|---|
| `categorical` | Categorical パレット + Sequential パレット |
| `sequential` | Sequential パレットのみ |
| `diverging` | Diverging パレットのみ |
| `threshold` | Sequential パレット + Diverging パレット |

`threshold` では `thresholdColors` で色を直接指定することもできます。`thresholdColors` を指定するとそれが優先され、省略すると `paletteId` のパレット全域から閾値で区切られた領域数ぶんの色を等間隔にサンプリングします。

Graph Builder の UI で scaleType を切り替えると、非互換になったパレットはその scaleType の既定パレットに自動でリセットされ、グラフはそのまま描画されます。API で非互換の `paletteId` を直接指定した場合は、描画時にエラーになりグラフが表示されません。

## aesthetic の固定値 {#aesthetic-fixed-values}

[Agent API](agent-api#tabsaddgraphlayertabid-layer) では、aesthetic プロパティは通常カラム名を指定してデータにマッピングします。カラムではなく定数を使いたい場合は以下のように指定します。

- **固定色**: `color`、`fill`、`stroke` に `{ fixedColor: '#FF0000' }` を指定します（CSS カラー文字列）
- **固定サイズ**: `size` に正の数値を指定します（例: `5`）。0 以下の値は警告とともに無視されます
- **固定アルファ**: `alpha` に 0（完全透明）から 1（完全不透明）の数値を指定します。範囲外の値は警告とともに無視されます

```javascript
await window.midas.tabs.addGraphLayer(tabId, {
  geom: { type: 'point' },
  aes: { x: 'weight', y: 'height', color: { fixedColor: '#3366CC' }, size: 8, alpha: 0.5 }
});
```

### 複数レイヤーに異なる固定色を設定する {#fixed-color-multi-layer}

各系列を個別のレイヤーとして追加し、それぞれに `fixedColor` を設定します。

```javascript
// レイヤー 1: 実測値（青）
await window.midas.tabs.addGraphLayer(tabId, {
  geom: { type: 'line' },
  aes: { x: 'date', y: 'actual', color: { fixedColor: '#3366CC' } }
});

// レイヤー 2: 予測値（赤）
await window.midas.tabs.addGraphLayer(tabId, {
  geom: { type: 'line' },
  aes: { x: 'date', y: 'predicted', color: { fixedColor: '#CC3333' } }
});
```

### 代替手段: カテゴリカル色分け {#color-categorical-alternative}

データが long 形式（1行1観測値、グループ列あり）の場合、`fixedColor` の代わりにグループ列を `color` にマッピングします。パレットが各グループに自動で色を割り当てます。

```javascript
// long 形式: 各行に "series" 列（"actual" や "predicted"）がある
await window.midas.tabs.addGraphLayer(tabId, {
  geom: { type: 'line' },
  aes: { x: 'date', y: 'value', color: 'series' }
});
```

系列数が動的な場合や、複数グラフで統一したパレット色を使いたい場合に適しています。

## Statistics と Label の連携 {#label-with-stats}

レイヤーで Statistics（Count、Summary、Bin 等）を使用すると、元のカラム値が集約結果に置き換わります。`aes.label` のカラムマッピングでは変換後のデータから元の値を参照できません。集約値をラベルとして表示するには、`aes.label` の代わりに `geom.defaults.labelContent` を設定します。

`labelContent` は `$` プレフィックス付きの stat 出力変数を参照します。

| 変数 | 説明 |
|------|------|
| `$y` | stat 変換後の Y 値（count、mean 等） |
| `$x` | X 値（ビン中心、カテゴリ名） |
| `$n` | 観測数（Bin stat と Count stat） |
| `$xmin` | ビンの下限（Bin stat） |
| `$xmax` | ビンの上限（Bin stat） |
| `$ymin` | インターバルの下限 |
| `$ymax` | インターバルの上限 |

```javascript
// Summary の平均値をラベルとして表示する
await window.midas.tabs.addGraphLayer(tabId, {
  geom: {
    type: 'label',
    defaults: {
      labelContent: { field: '$y', format: '.1f' }
    }
  },
  stats: [{ type: 'summary', params: { outputs: [{ fun: 'mean', to: 'y' }] } }],
  aes: { x: 'category', y: 'value' }
});
```

`labelContent` オブジェクトのプロパティ:

| プロパティ | 型 | 説明 |
|-----------|------|------|
| `field` | `string` | `$` プレフィックス付き変数（上表参照）またはカラム ID |
| `format` | `string` | [d3-format](https://d3js.org/d3-format) 書式指定（省略時はデータ型から自動推定）。代表的な書式: `.1f`（小数1桁）、`.0%`（パーセント、小数なし）、`,.0f`（桁区切り） |
| `prefix` | `string` | フォーマット値の前に付加するテキスト |
| `suffix` | `string` | フォーマット値の後に付加するテキスト |

## 座標系 {#coordinates}

座標系はグラフレベルの設定で、[`tabs.configureGraph`](agent-api#tabsconfiguregraphtabid-config) または [`reports.addGraph`](agent-api#reportsaddgraphreportid-config) の `coordinates` フィールドに指定します。

- `'cartesian'`（デフォルト）— 標準的な直交座標系
- `'flipped'` — X 軸と Y 軸を入れ替えます。カテゴリラベルが長い横棒グラフで読みやすくなります

GUI では Graph Builder の **Coordinate System** セクションに対応します。表示例は [Custom Graph: 軸の入れ替え](custom-graph#flipping-axes) を参照してください。

### flipped 座標系での scales.x / scales.y {#flipped-scales}

flipped 座標系では `aes.y` のデータが物理 X 軸（横）に、`aes.x` のデータが物理 Y 軸（縦）に描画されます。`scales.x` / `scales.y` の設定は、項目によって参照する軸が異なります。

- スケール種別と tick の設定（`type`、`domain`、`ticks`、`zoomEnabled`）は物理的な画面軸に適用されます。flipped でも `scales.x` が横軸、`scales.y` が縦軸を制御します
- `title` はデータの軸に追従します。`scales.x.title` は `aes.x` のデータの軸（flipped では縦軸）に、`scales.y.title` は `aes.y` のデータの軸（flipped では横軸）に表示されます

```javascript
// 横棒グラフ: aes.x にカテゴリ、aes.y に数値をマッピングした場合
await window.midas.tabs.configureGraph(tabId, {
  coordinates: 'flipped',
  scales: {
    x: { title: 'Product' },      // aes.x の軸 — flipped では縦軸に表示
    y: { title: 'Sales (USD)' }   // aes.y の軸 — flipped では横軸に表示
  }
});
```

副 Y 軸（`scales.y2`）は flipped 座標系では無効になります。

## See also {#see-also}

- **[高度なグラフ作成](custom-graph)** - Custom Graph の使い方とチュートリアル
- **[グラフの作成](graph-basics)** - Graph Builder の基本操作
