Custom Graph リファレンス

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

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

Geometry(形状)

GeometryDescription
Point (Scatter)Displays data as individual points.
LineConnects data points with lines. Draws an interval band automatically when ymin/ymax are present.
BarVertical bars for categorical data. Use Fill (not Color) to change bar color.
AreaFilled 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 BarError 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.
ContourDraws a curve from a series of points. Used for Cook's distance contours in regression diagnostics.
Density 2D2D 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.

Geometry と aesthetic の互換性

各 Geometry は特定の aesthetic(位置・色・サイズなどの視覚マッピング)のみを受け付けます。対応していない aesthetic を指定しても効果はありません。

Geometryxycolorfillstrokesizeshapealphalinetypeyminymaxlabel
pointRR
lineRR
barRR
areaRR
tileRR
stepRR
ribbonRRR
errorbarRRR
vline
hline
contourRR
density2dRR
textRR
labelRR

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

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

Statistics(統計変換)

StatisticsDescription
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 MeanCalculates the mean of X values. Use with vline geom to draw a vertical reference line.
X MedianCalculates the median of X values. Use with vline geom to draw a vertical reference line.
Y MeanCalculates 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.

Statistics のパラメータ

各 Statistic は tabs.addGraphLayer / tabs.updateGraphLayerstats 配列に params オブジェクトを渡します。以下の表は各 Statistic のパラメータ名、TypeScript 型、デフォルト値、説明の一覧です。

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 を参照してください。

Identity (No transformation)

No parameters.

Bin (Histogram)

NameTypeDefaultDescription
binsnumber30Number of bins (5-100). Ignored when binwidth is specified.
binwidthnumberWidth 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).
boundarynumberPosition of a bin edge in X-axis units. Bins are aligned so that one edge falls on this value.
centernumberPosition of a bin center in X-axis units. Takes precedence over boundary.

Time Bin (Datetime Histogram)

NameTypeDefaultDescription
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)

NameTypeDefaultDescription
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.
sebooleantrueWhen 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.
spannumber0.75LOESS span: fraction of points in each local neighborhood (0.1-1.0). Larger values produce smoother curves. Ignored when method is lm.
levelnumber0.95Interval 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)

No parameters.

Density (KDE)

NameTypeDefaultDescription
bandwidthnumberKernel 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)

NameTypeDefaultDescription
outputsSummaryOutputDef[][{ 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'.
completebooleanfalseWhen 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)

NameTypeDefaultDescription
confLevelnumber0.95Confidence 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

NameTypeDefaultDescription
labelstring'Mean: {value}'Label template for the reference line. {value} is replaced with the computed mean.

X Median

NameTypeDefaultDescription
labelstring'Median: {value}'Label template for the reference line. {value} is replaced with the computed median.

Y Mean

NameTypeDefaultDescription
offsetnumber0Number 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).
labelstring'Mean: {value}'Label template for the reference line. {value} is replaced with the computed value.

Cumulative Sum (Pareto)

NameTypeDefaultDescription
normalizebooleanfalseWhen true, scales the cumulative sum so the total equals 100 (percent).

Sort (Pareto)

NameTypeDefaultDescription
order'ascending' | 'descending''descending'Sort direction applied to Y values.
limitnumberKeep 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)

No parameters.

QQ (Normal Q-Q Plot)

NameTypeDefaultDescription
showReferenceLinebooleantrueWhen 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)

NameTypeDefaultDescription
multiplynumber1Multiplier applied to Y. For example, -1 flips a histogram for a population pyramid.
addnumber0Offset added after multiplication.

Palettes(パレット)

layers[].scalescolor / fill チャネルで paletteId に指定できる値の一覧です。API での設定方法は Agent API を参照してください。

Categorical

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

IDNameColors
midas-defaultMIDAS Default12
tableau10Tableau 1010
d3-category10D3 Category1010

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

Sequential

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

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

IDNameColors
bluesBlues9
greensGreens9
greysGreys9
purplesPurples9
ylorrdYellow-Orange-Red9
viridisViridis10
plasmaPlasma10
infernoInferno10
magmaMagma10

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

Diverging

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

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

IDNameColors
rdbuRed-Blue11
brbgBrown-Teal11

デフォルトは rdbu です。

scaleType と paletteId の互換性

scaleType使用可能な paletteId
categoricalCategorical パレット + Sequential パレット
sequentialSequential パレットのみ
divergingDiverging パレットのみ
thresholdSequential パレット + Diverging パレット

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

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

aesthetic の固定値

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

  • 固定色: colorfillstroke{ fixedColor: '#FF0000' } を指定します(CSS カラー文字列)
  • 固定サイズ: size に正の数値を指定します(例: 5)。0 以下の値は警告とともに無視されます
  • 固定アルファ: alpha に 0(完全透明)から 1(完全不透明)の数値を指定します。範囲外の値は警告とともに無視されます
await window.midas.tabs.addGraphLayer(tabId, {
  geom: { type: 'point' },
  aes: { x: 'weight', y: 'height', color: { fixedColor: '#3366CC' }, size: 8, alpha: 0.5 }
});

複数レイヤーに異なる固定色を設定する

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

// レイヤー 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' } }
});

代替手段: カテゴリカル色分け

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

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

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

Statistics と Label の連携

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

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

変数説明
$ystat 変換後の Y 値(count、mean 等)
$xX 値(ビン中心、カテゴリ名)
$n観測数(Bin stat と Count stat)
$xminビンの下限(Bin stat)
$xmaxビンの上限(Bin stat)
$yminインターバルの下限
$ymaxインターバルの上限
// 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 オブジェクトのプロパティ:

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

座標系

座標系はグラフレベルの設定で、tabs.configureGraph または reports.addGraphcoordinates フィールドに指定します。

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

GUI では Graph Builder の Coordinate System セクションに対応します。表示例は Custom Graph: 軸の入れ替え を参照してください。

flipped 座標系での scales.x / scales.y

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

  • スケール種別と tick の設定(typedomaintickszoomEnabled)は物理的な画面軸に適用されます。flipped でも scales.x が横軸、scales.y が縦軸を制御します
  • title はデータの軸に追従します。scales.x.titleaes.x のデータの軸(flipped では縦軸)に、scales.y.titleaes.y のデータの軸(flipped では横軸)に表示されます
// 横棒グラフ: 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