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.
CrossbarRectangle spanning ymin to ymax with a line at y. Combine with the Summary statistic to draw an interval around a center value (e.g. mean and mean±SE).
Box PlotBox-and-whisker plot per group: box from Q1 to Q3, median line, whiskers, and individual points beyond the whiskers. Use with the Boxplot statistic.
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
crossbarRRRR
boxplotRRRR
vline
hline
contourRR
density2dRR
textRRR
labelRR

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

  • Required の aesthetic はカラムへのマッピングか Statistics による供給が必要です。
  • colorfill の違い: Bar と Tile は塗りつぶしに fill を使います(color ではありません)。Area は両方を受け付けます — color は輪郭線、fill は塗りつぶしです。Ribbon は輪郭線を描画せず、color が塗りつぶし色を決めます。Ribbon の fill は threshold カラースケールを使う場合にのみ参照されます。Crossbar と Box Plot は矩形の塗りつぶしに fill を、線の色(Box Plot では箱の枠線・ひげ・中央値線・ひげの外の点)に color を使います。
  • stroke: Point のみが対応しています。ポイントの輪郭色を設定します。
  • shape: Box Plot では、割り当てた列の水準ごとに箱が分割され(colorfill と同様)、ひげの外の点が水準ごとに異なるマーカー形状で描かれます。size はひげの外の点にのみ適用されます。
  • ymin / ymax: Line は両方が存在するとインターバルバンドを描画します。Ribbon・Errorbar・Crossbar では必須です。
  • label: Text ではカラムへのマッピングが必須です。Label では aes.labelgeom.defaults.labelContent のどちらかが必要です。

Geometry と position の互換性

各 Geometry が受け付ける position(位置調整)は異なります。各 position type の意味は Position を参照してください。表にない position type を tabs.addGraphLayer / tabs.updateGraphLayer で指定すると INVALID_INPUT エラーになります。position を省略した場合のデフォルトは bar が stack、それ以外の geom が identity です。

GeometryAllowed positions
pointidentity, dodge, jitter
lineidentity
baridentity, stack, dodge, fill
areaidentity, stack, fill
tileidentity
stepidentity
ribbonidentity
errorbaridentity, dodge, jitter
crossbaridentity, dodge
boxplotidentity, dodge
vlineidentity
hlineidentity
contouridentity
density2didentity
textidentity
labelidentity

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.
Boxplot (Quartiles + Whiskers)Computes the median, quartiles (linear interpolation), whisker ends (most extreme data values within coef × IQR of the quartiles), and the individual data values beyond the whiskers for each group. Use with the Box Plot geometry.
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 Prediction interval in the glossary 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); no curve is drawn when this is 0, e.g. a constant middle 50%, identical values, or a single observation), 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, n-1 denominator), '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.

Boxplot (Quartiles + Whiskers)

NameTypeDefaultDescription
coefnumber1.5Whisker length as a multiple of the IQR. Whiskers extend to the most extreme data values within coef × IQR of the quartiles; data values beyond the whiskers are drawn as individual points.

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 aesthetic で 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 を直接指定した場合は、描画時にエラーになりグラフが表示されません。

この互換性の判定には実効のスケール種別を使います。数値でない列に sequential / diverging を指定した場合、実効種別は categorical になるため、指定した種別の上では適合するパレットでもエラーになることがあります。エラーメッセージには実効種別へ解決された経緯が示されます。

Geometry の固定設定

aesthetic はカラムを視覚属性にマッピングします。データに依存しない固定の色・サイズ・不透明度は aes ではなく geom.defaults に置きます。Graph Builder の UI では、これらはレイヤーの Geometry セクションで設定します。

  • 固定色: 線・点・文字の色は geom.defaultscolor、bar・area・tile・ribbon・crossbar・boxplot の塗りつぶし色は geom.defaultsfill に CSS カラー文字列を指定します。tile の枠線色は geom.defaultsstroke です。crossbar と boxplot の線色(枠線・中心線・ひげ)も stroke で指定します(geom.defaultscolor キーはありません)
  • 固定サイズ: geom.defaultssize(point)、strokeWidth(line・step)、fontSize(text・label)に指定します
  • 固定不透明度: geom.defaultsalpha に指定します。0 が完全透明、1 が完全不透明です
await window.midas.tabs.addGraphLayer(tabId, {
  geom: { type: 'point', defaults: { color: '#3366CC', size: 8, alpha: 0.5 } },
  aes: { x: 'weight', y: 'height' }
});

固定値を aes に渡すと(例: aes.color: { fixedColor: ... }aes.size: 8INVALID_INPUT エラーになります。aes.* はカラム名のみを受け付けます。

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

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

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

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

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

データが long 形式(1行1観測値、グループ列あり)の場合、固定色の代わりにグループ列を 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その点の統計量が計算に使った観測数を表す(欠損は除く。Summary・Boxplot・Bin 系は非有限値も除く)。Count・Bin・Summary・Boxplot などが対象で、Smooth(回帰曲線)では出力しない
$xminビンの下限(Bin stat)
$xmaxビンの上限(Bin stat)
$yminインターバルの下限
$ymaxインターバルの上限
$q1第 1 四分位数(Boxplot stat)
$q3第 3 四分位数(Boxplot stat)
// 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