Custom Graph リファレンス
Custom Graph で利用可能な Geometry と Stat の一覧です。各項目の詳細は、layer の設定内のヘルプボタン(?)で確認できます。
Geometry
| 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. |
| Crossbar | Rectangle spanning ymin to ymax with a line at y. Combine with the Summary stat to draw an interval around a center value (e.g. mean and mean±SE). |
| Box Plot | Box-and-whisker plot per group: box from Q1 to Q3, median line, whiskers, and individual points beyond the whiskers. Use with the Boxplot stat. |
| Vertical Line (Reference) | Fixed vertical reference line. |
| Horizontal Line (Reference) | Fixed horizontal reference line. |
| Sloped Line (Reference) | Straight reference line y = intercept + slope × x, drawn where it crosses the plot area. The default is y = x. The line does not widen the axis ranges, so it is not visible when it misses the plot area. It ignores column mappings, the layer filter, and the stat. Not drawn when either axis is categorical. On a log or sqrt axis the line can appear curved. When the x or y axis is a date or datetime axis, the values on that axis are milliseconds since 1970-01-01T00:00:00Z. |
| Density 2D | 2D kernel density estimation as contour lines. For 1D density curves, use the Density (KDE) stat. |
| Text (Label) | Displays text labels at data points. Requires a column mapped to the Label aesthetic or a Label Content field. |
| Label (Annotation) | Displays text boxes with leader lines at data points. |
Geometry と aesthetic の互換性
各 Geometry は特定の aesthetic(位置・色・サイズなどの視覚マッピング)のみを受け付けます。対応していない 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 | |||||||
| crossbar | R | R | • | • | • | R | R | |||||
| boxplot | R | R | • | • | • | • | • | R | R | |||
| vline | • | • | ||||||||||
| hline | • | • | ||||||||||
| abline | ||||||||||||
| density2d | R | R | • | |||||||||
| text | R | R | • | • | • | • | ||||||
| label | R | R | • | • | • |
R = required(必須), ○ = optional(指定時に追加の動作が発生), • = supported(対応)
- Required の aesthetic はカラムへのマッピングか stat による供給が必要です。
- color と fill の違い: Bar と Tile は塗りつぶしに
fillを使います(colorではありません)。Area は両方を受け付けます —colorは輪郭線、fillは塗りつぶしです。Ribbon は輪郭線を描画しません。fillに列を割り当てるとfillの値で、fillに列が無ければcolorの値で塗りつぶします。Crossbar と Box Plot は矩形の塗りつぶしにfillを、線の色(Box Plot では箱の枠線・ひげ・中央値線・ひげの外の点)にcolorを使います。 - stroke: Point のみが対応しています。ポイントの輪郭色を設定します。
- shape: Box Plot では、割り当てた列の水準ごとに箱が分割され(
colorやfillと同様)、ひげの外の点が水準ごとに異なるマーカー形状で描かれます。size はひげの外の点にのみ適用されます。 - ymin / ymax: Line は両方が存在するとインターバルバンドを描画します。Ribbon・Errorbar・Crossbar・Box Plot では必須です。
- q1 / q3: Box Plot は箱の上端と下端に四分位数を必要とします。この 2 つはカラムにマッピングできないため表に列がなく、Boxplot stat の出力だけが供給元です。
- label: Text と Label では
aes.labelかgeom.defaults.labelContentのどちらかが必要です。 - group: 色・形・線種を変えないため表に列がありません。Text は group を受け付けます。
- weight: どの Geometry の描画にも影響しないため表に列がありません。行の頻度重み(その行が何行分の観測に相当するか)を数値カラムで指定し、重みに対応した stat(ROC Curve)だけが読み取ります。tooltip の
$nは重みを合計せず、計算に使った行数を数えます。
Geometry と position の互換性
各 Geometry が受け付ける position(位置調整)は異なります。各 position type の意味は Position を参照してください。表にない position type を tabs.addGraphLayer / tabs.updateGraphLayer で指定すると INVALID_INPUT エラーになります。position を省略した場合のデフォルトは bar が stack、それ以外の geom が identity です。
| Geometry | Allowed positions |
|---|---|
| point | identity, dodge, jitter |
| line | identity |
| bar | identity, stack, dodge, fill |
| area | identity, stack, fill |
| tile | identity |
| step | identity |
| ribbon | identity |
| errorbar | identity, dodge, jitter |
| crossbar | identity, dodge |
| boxplot | identity, dodge |
| vline | identity |
| hline | identity |
| abline | identity |
| density2d | identity |
| text | identity, dodge, stack, fill |
| label | identity |
position は Geometry だけでなく stat とも組み合わせが検証されます。次の表に載っている stat は、記載された position とだけ組み合わせられます。表にない stat はすべての position を使えます。
| Stat | Allowed positions |
|---|---|
| Boxplot (Quartiles + Whiskers) | identity, dodge, jitter |
| QQ (Normal Q-Q Plot) | identity, jitter |
Y に尺度が nominal か ordinal の列を割り当てた layer では、上の表にあっても stack と fill を使えません。
グループ
MIDAS は、点をグループに分け、stat・position・Geometry のどれもグループごとに処理します。グループは、grouping aesthetic に割り当てた列の値がすべて同じ点の集まりです。grouping aesthetic は、scale が categorical の aesthetic です。stroke・shape・linetype・group は常に grouping aesthetic で、color と fill は MIDAS が描画に使う scale が categorical のときだけ grouping aesthetic になります。scaleType を省略したときと、数値でない列に sequential か diverging を指定したときに MIDAS が使う scale は、Agent API の説明にあります。Geometry が描画に使わない grouping aesthetic の列も、グループを決めます。
グループごとに処理するので、Line・Step・Area・Ribbon はグループごとに線や面を描きます。たとえば Line の color に 3 種類の値を持つ列を割り当てると、線は 3 本になります。position の Stack・Dodge・Fill は、グループを系列として積み上げ、横に並べます。
Geometry と連続 color scale
identity・sort・transform・cumsum・qq の stat は、出力する点が入力の点 1 つに対応するので、点ごとにその値から色を決めます。Line・Area・Step・Ribbon は、グループごとに、色を X 軸に沿って変化するグラデーションにします。flipped coordinate system では Y 軸に沿います。グラデーションの色は各データ点の位置でその点の値から決まり、点と点の間は補間されます。
Bin・Density・Smooth のように点を集約する stat は、連続 color scale の color と fill の値を区別せずに計算します。値ごとに別のグループにして計算したい場合は、その aesthetic の scaleType を categorical にします。
Bar は点ごとに矩形を描くので、連続 color scale でも積み上げます。
Stat(統計変換)
| Stat | 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 the values of the aesthetic selected as Input (input, Y by default) with the aggregate function of each output, for each combination of the values of X, of the grouping aesthetics, and of Y when Y is neither the Input nor an output target. |
| 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 combination of X and the group. Use with the Box Plot geometry. |
| Survival (Kaplan-Meier) | Computes Kaplan-Meier survival estimates. Map the time to X (values of 0 or more) and the event indicator to Y (1 = event, 0 = censored). |
| ROC Curve | Computes ROC curve points (false positive rate vs true positive rate) from binary labels and scores. Ties in the score are merged into one threshold, so the area under the curve matches the AUC computed with ties counted as one half. Map the score to X and the label to Y — 0/1 values, or proportions of positives in [0, 1] for aggregated data. Optionally map a frequency weight (e.g., the number of trials behind each proportion) to Weight. |
| 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 categories by the sum of their Y values, in descending or ascending 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 i-th smallest value, i = 1, ..., n) for the theoretical quantiles. |
| Transform (Linear) | Applies linear transformation (multiply and add) to Y values. |
| Cook's Distance Contour | Computes one side of the Cook's distance contour r = ±√(D·p·(1 − h)/h) for a plot of standardized residuals r (y) against leverage h (x). Each residual must be divided by s·√(1 − h), where h is the leverage of its own observation and s is the scale in the definition of the Cook's distance, estimated from all observations (an internally studentized residual, such as the standardized residuals of the regression diagnostics). An observation on the curve then has Cook's distance D = r²·h / (p·(1 − h)); externally studentized residuals do not satisfy this relation. The curve spans leverage from 0.001 to 0.5, widened to the smallest and largest x values strictly between 0 and 1. With a grouping aesthetic, each group gets its own curve, whose range is widened by the x values of that group only. The curve does not widen the axis ranges set by the other layers. Use with the line geom, one layer for each side. |
Stat のパラメータ
各 stat は tabs.addGraphLayer / tabs.updateGraphLayer の stats 配列に params オブジェクトを渡します。以下の表は各 stat のパラメータ名、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?)は省略可能を表します。各 stat の前提・限界・ユースケースの詳細は Custom Graph を参照してください。
Identity (No transformation)
No parameters.
Bin (Histogram)
| Name | Type | Default | Description |
|---|---|---|---|
bins | number | 30 | Number of bins (1-100). Ignored when binwidth is specified. When integerBins applies, determines the bin width instead, so the number of bins can differ. With facets, the bin width and edges are determined from the values of all panels that share the x axis, so a panel whose values cover a narrower range shows fewer bins. |
binwidth | number | — | Width of each bin in X-axis units (milliseconds for a date or datetime x). Takes precedence over bins. |
yScale | 'count' | 'density' | 'proportion' | 'count' | Y-axis scale: 'count' reports bin counts; 'density' reports probability density (bin counts divided by the number of binned observations × binwidth, so the area over equal-width bins equals 1); 'proportion' reports each bin's share of its own group, so the values of every group sum to 1. With a categorical aesthetic such as fill, both 'density' and 'proportion' use a per-group denominator, so each group reaches an area of 1 (density) or a total of 1 (proportion) on its own; stacking groups whose denominators differ produces a total with no interpretation. Both denominators count the observations that were binned, which excludes missing values of the binned column. |
boundary | number | — | Position of a bin edge in X-axis units (milliseconds since 1970-01-01T00:00:00Z for a date or datetime x). Bins are aligned so that one edge falls on this value. When boundary and center are omitted, the first bin starts at the minimum of the binned values; with facets, at the minimum over all panels that share the x axis. |
center | number | — | Position of a bin center in X-axis units (milliseconds since 1970-01-01T00:00:00Z for a date or datetime x). Takes precedence over boundary. |
integerBins | boolean | false | When true and every binned value is an integer, each bin covers the same number of whole integers: the bin width is binwidth rounded up to an integer, or without binwidth, the range of the values divided by bins and rounded up, and never less than 1; bin edges fall halfway between integers, starting 0.5 below the minimum. Without binwidth, every integer gets its own bin when the range is no larger than bins, and the number of bins can be bins + 1. The last bin can extend past the maximum and then covers fewer observed integers than the other bins. boundary and center are not used in that case. With a width of 1, the bin centers become the axis ticks of ticks.fromLayer; with a wider bin, the axis uses its usual ticks. With facets, the width and edges are determined from the values of all panels that share the x axis, and the range and the integer check cover the values of all those panels. Has no effect when some value is not an integer or when x is a date or datetime column. |
Time Bin (Datetime Histogram)
| 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 (with facets, the range of all panels that share the x axis), and chooses '1day' or longer for a date column. For a datetime column, every interval bins by boundaries in the viewer's local time, the same boundaries as the time axis ticks: minutes and hours on the local clock, local midnight for '1day', Sunday midnight for '1week', and the start of the month, quarter (January, April, July, October), or year; viewed in a time zone with a different UTC offset, an observation moves to another bin when its local time falls in a different bin there. For a date column, bins follow the calendar dates themselves and do not depend on the time zone. Bin widths follow the calendar (e.g. 28-31 days for months) and, for a datetime column, daylight saving time (e.g. a 23-hour day or a 5-hour '6hour' bin when the clock moves forward). |
yScale | 'count' | 'density' | 'proportion' | 'count' | Y-axis scale: 'count' reports bin counts (when bins span unequal durations, such as months, counts reflect both the rate and the length of each bin); 'density' reports probability density (bin counts divided by the number of binned observations × each bin's actual width in milliseconds, so the total area equals 1); 'proportion' reports each bin's share of its own group, so the values of every group sum to 1 (the bin width does not enter, so when bins span unequal durations the share also reflects the length of each bin). With a categorical aesthetic such as fill, both 'density' and 'proportion' use a per-group denominator, so each group reaches an area of 1 (density) or a total of 1 (proportion) on its own; stacking groups whose denominators differ produces a total with no interpretation. Both denominators count the observations that were binned, which excludes missing values of the binned column. |
Smooth (Regression)
| Name | Type | Default | Description |
|---|---|---|---|
method | 'lm' | 'loess' | 'loess' | Smoothing method: 'lm' for ordinary least squares, 'loess' for locally weighted regression (tricube kernel, local linear). A separate curve is fit for each group, a set of points that share the values of the grouping aesthetics (aesthetics with a categorical scale, such as color). |
se | boolean | true | When true, emits ymin/ymax for an interval band (Line geom draws the band automatically). |
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 | 95 | Interval level in percent (50-99.99), the same unit as confidenceLevel of models.run(). For example, 95 for a 95% interval. For loess, the interval uses simplified degrees of freedom (df = n - tr(L)) and does not account for smoothing bias, so at large spans the actual coverage can deviate from this nominal level. |
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)
| Name | Type | Default | Description |
|---|---|---|---|
bandwidth | number | — | Kernel bandwidth in X-axis units. When omitted, bandwidth is selected automatically, separately for each group and, with facets, for each panel, 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. |
yScale | 'density' | 'count' | 'density' | Y-axis scale: 'density' reports the estimated probability density; with a categorical aesthetic such as color, each group's density is estimated from that group alone. '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', which normalizes per group on both sides. The binwidth is computed per group from its own range and observation count, so with a categorical aesthetic the 'count' curves of different groups use different binwidths and their heights are not directly comparable. |
Summary (Aggregation)
| 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, 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 aesthetic: 'y', 'ymin', or 'ymax' for positions, or 'fill', 'color', 'size', or 'alpha' to drive that scale with the aggregated value. p (0-1) selects the quantile for 'quantile'; when omitted, 0.5 (the median) is used. k (default 1) is the SD multiplier for 'mean_plus_k_sd' / 'mean_minus_k_sd'. |
complete | boolean | false | When true, after aggregation, adds a point whose aggregated value is 0 at each X value that has no data. When the column assigned to Y is used as a position without being aggregated (as in a heatmap), the points are added at the X and Y pairs that have no data. When the grouping aesthetics split the points into groups, the points are added for each group. Ignored with facets, where the facet's complete setting applies. |
Boxplot (Quartiles + Whiskers)
| Name | Type | Default | Description |
|---|---|---|---|
coef | number | 1.5 | Whisker 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)
| Name | Type | Default | Description |
|---|---|---|---|
confLevel | number | 95 | Confidence level in percent (50-99.99), the same unit as confidenceLevel of models.run(), 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 lower bound stays positive while S(t) is positive and the upper bound is clipped to 1; at time points where S(t) is exactly 0 or 1 the interval collapses to that value. |
ROC Curve
| Name | Type | Default | Description |
|---|---|---|---|
showReferenceLine | boolean | true | When true, draws the diagonal reference line y = x, the ROC curve of a classifier that assigns labels independently of the data. |
X Mean
| Name | Type | Default | Description |
|---|---|---|---|
label | string | 'Mean: {value}' | Label template for the reference line. {value} is replaced with the computed mean. |
X Median
| Name | Type | Default | Description |
|---|---|---|---|
label | string | 'Median: {value}' | Label template for the reference line. {value} is replaced with the computed median. |
Y Mean
| 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, and -3 at mean − 3 × SD. |
label | string | 'Mean: {value}'; 'Mean + k*SD: {value}' when offset is a positive k, and 'Mean - k*SD: {value}' when offset is -k | Label template for the reference line. {value} is replaced with the computed value. |
Cumulative Sum (Pareto)
| Name | Type | Default | Description |
|---|---|---|---|
normalize | boolean | false | When true, scales the cumulative sum so the total equals 100 (percent). |
Sort (Pareto)
| Name | Type | Default | Description |
|---|---|---|---|
order | 'ascending' | 'descending' | 'descending' | Order of the categories by the sum of their Y values. |
limit | number | — | Keep only the top N categories after sorting. Omit to keep all categories. |
displayOrder | 'alphabetical' | — | Re-sorts the kept categories into the default category order of the x axis. Only 'alphabetical' is supported; omit to keep the sort order selected by 'order'. |
ECDF (Empirical CDF)
No parameters.
QQ (Normal Q-Q Plot)
| 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' is the line through (Φ⁻¹(0.25), Q1) and (Φ⁻¹(0.75), Q3), where Φ⁻¹ is the standard normal quantile function and Q1 and Q3 are the sample quartiles with linear interpolation (the same as the 'quantile' summary); use it for raw data on its original scale. When points are split into groups by color, fill, stroke, shape, linetype, or group, each group with 4 or more points gets its own line from its own quartiles. 'identity' is y = x; use it only when the input is already standardized (e.g., z-scores centered at 0 and scaled by SD) within each group. |
Transform (Linear)
| 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. |
Cook's Distance Contour
| Name | Type | Default | Description |
|---|---|---|---|
distance | number | 0.5 | Cook's distance D of the contour. |
parameterCount | number | 2 | Number of coefficients p of the model, counting the intercept and not counting the dispersion parameter. For a GLM or Linear Regression model, it is diagnosticSummary.nObservations − diagnosticSummary.degreesOfFreedom from models.describe. |
residualSign | 'positive' | 'negative' | 'positive' | Side of the contour to draw: positive or negative standardized residuals. |
Palettes(パレット)
layers[].scales の color / fill aesthetic で paletteId に指定できる値の一覧です。API での設定方法は Agent API を参照してください。
Categorical
カテゴリカル変数の色分けに使います。scaleType: 'categorical' で指定します。
| ID | Name | Colors |
|---|---|---|
midas-default | MIDAS Default | 12 |
tableau10 | Tableau 10 | 10 |
d3-category10 | D3 Category10 | 10 |
デフォルトは midas-default です。
Sequential
連続変数や順序尺度の変数に使います。scaleType: 'sequential' で指定します。
scaleType: 'categorical' と 'threshold' でも使用できます。カテゴリ数または閾値で区切られた領域数ぶんの色をパレット全域から等間隔にサンプリングします。categorical では、値が欠損しているグループをカテゴリ数に数えず、このグループに灰色を割り当てます。
| 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
中心値からの乖離を両方向に表す変数に使います。scaleType: 'diverging' で指定します。
scaleType: 'threshold' でも使用できます。閾値で区切られた領域数ぶんの色をパレット全域から等間隔にサンプリングします。
| ID | Name | Colors |
|---|---|---|
rdbu | Red-Blue | 11 |
brbg | Brown-Teal | 11 |
デフォルトは rdbu です。
scaleType と paletteId の互換性
| scaleType | 使用可能な paletteId |
|---|---|
categorical | Categorical パレット + Sequential パレット |
sequential | Sequential パレットのみ |
diverging | Diverging パレットのみ |
threshold | Sequential パレット + Diverging パレット |
threshold では thresholdColors で色を直接指定することもできます。thresholdColors を指定するとそれが優先され、省略すると paletteId のパレット全域から閾値で区切られた領域数ぶんの色を等間隔にサンプリングします。
Graph Builder の UI で scaleType を切り替えると、非互換になったパレットはその scaleType の既定パレットに自動でリセットされ、グラフはそのまま描画されます。
この互換性の判定には実効の scale の種別を使います。数値でない列に sequential / diverging を指定した場合、実効種別は categorical になるため、指定した種別の上では適合するパレットでもエラーになることがあります。
Geometry の固定設定
aes はカラムを aesthetic にマッピングします。データに依存しない固定の色・サイズ・不透明度は aes ではなく geom.defaults に置きます。Graph Builder の UI では、これらは layer の Geometry セクションで設定します。
- 固定色: 線・点・文字の色は
geom.defaultsのcolor、bar・area・tile・ribbon・crossbar・boxplot の塗りつぶし色はgeom.defaultsのfillに CSS カラー文字列を指定します。tile の枠線色はgeom.defaultsのstrokeです。crossbar と boxplot の線色(枠線・中心線・ひげ)もstrokeで指定します(geom.defaultsにcolorキーはありません) - 固定サイズ:
geom.defaultsのsize(point の半径)、strokeWidth(線を描く Geometry の線幅)、fontSize(text・label)に指定します。どの Geometry がどのキーを持つかは Geometry ごとのgeom.defaultsキー の表で確認できます - 固定不透明度:
geom.defaultsのalphaに指定します。0 が完全透明、1 が完全不透明です
await window.midas.tabs.addGraphLayer(tabId, {
geom: { type: 'point', defaults: { color: '#3366CC', size: 8, alpha: 0.5 } },
aes: { x: 'weight', y: 'height' }
});
Geometry ごとの geom.defaults キー
geom.defaults に指定できるキーは Geometry ごとに異なります。以下の表は各 Geometry のキー名、型、範囲、既定値、説明の一覧です。Graph Builder の UI で layer の Geometry セクションに並ぶ項目と同じ集合で、省略したキーは既定値で描画します。Range 列は Graph Builder の UI で選べる範囲です。
構造を持つ設定 labelContent は表に含まれません。Text と Label の labelContent は stat の出力や列の値を書式付きでラベルにする設定で、UI では layer のカードの Label Content 欄で設定します。詳細は Stat と Label の連携 で説明します。
Point (Scatter)
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
color | string (CSS color) | — | '#4682b4' | Point color used when no column is mapped to the color aesthetic. Any CSS color string. |
size | number | 1–20 | 5 | Point radius in pixels, used when no column is mapped to the size aesthetic. |
alpha | number | 0–1 | 0.7 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Line
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
color | string (CSS color) | — | '#4682b4' | Line color used when no column is mapped to the color aesthetic. Any CSS color string. |
strokeWidth | number | 1–5 | 2 | Line width in pixels. |
lineType | 'solid' | 'dashed' | 'dotted' | — | 'solid' | Dash pattern of the line. |
alpha | number | 0–1 | 0.9 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Bar
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
fill | string (CSS color) | — | '#4682b4' | Bar fill color used when no column is mapped to the fill aesthetic. Any CSS color string. |
width | number | 0.1–1 | 0.8 | Bar width as a fraction of the category band width. |
alpha | number | 0–1 | 0.8 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Area
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
fill | string (CSS color) | — | '#4682b4' | Fill color of the area used when no column is mapped to either the fill or the color aesthetic. Any CSS color string. |
alpha | number | 0–1 | 0.5 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Tile (Heatmap)
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
fill | string (CSS color) | — | '#cccccc' | Cell fill color used when no column is mapped to the fill aesthetic. Any CSS color string. |
stroke | string (CSS color) | — | '#ffffff' | Border color of each cell. Any CSS color string. |
strokeWidth | number | 0–5 | 0.5 | Border width of each cell in pixels. 0 draws no border. |
alpha | number | 0–1 | 1 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Step (Kaplan-Meier)
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
color | string (CSS color) | — | '#4682b4' | Line color used when no column is mapped to the color aesthetic. Any CSS color string. |
strokeWidth | number | 1–5 | 2 | Line width in pixels. |
lineType | 'solid' | 'dashed' | 'dotted' | — | 'solid' | Dash pattern of the line. |
alpha | number | 0–1 | 0.9 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Ribbon (Confidence Band)
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
fill | string (CSS color) | — | '#4682b4' | Band fill color used when no column is mapped to either the fill or the color aesthetic. Any CSS color string. |
curveType | 'linear' | 'stepAfter' | 'stepBefore' | — | 'linear' | How the band edges connect consecutive points: straight segments, or a step that changes after or before each x value. |
alpha | number | 0–1 | 0.2 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Error Bar
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
color | string (CSS color) | — | '#333333' | Color of the bars and caps used when no column is mapped to the color aesthetic. Any CSS color string. |
strokeWidth | number | 0.5–5 | 1.5 | Width of the bars and caps in pixels. |
capWidth | number | 0–20 | 8 | Width of the caps at ymin and ymax in pixels. 0 draws no caps. |
alpha | number | 0–1 | 0.8 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Crossbar
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
fill | string (CSS color) | — | '#4682b4' | Fill color of the rectangle used when no column is mapped to the fill aesthetic. Any CSS color string. |
stroke | string (CSS color) | — | '#333333' | Color of the outline and the center line used when no column is mapped to the color aesthetic. Any CSS color string. |
width | number | 0.1–1 | 0.6 | Rectangle width as a fraction of the category band width. |
strokeWidth | number | 0.5–5 | 1.5 | Width of the outline and the center line in pixels. |
alpha | number | 0–1 | 0.8 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Box Plot
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
fill | string (CSS color) | — | '#4682b4' | Box fill color used when no column is mapped to the fill aesthetic. Any CSS color string. |
stroke | string (CSS color) | — | '#333333' | Color of the box outline, the median line, and the whiskers used when no column is mapped to the color aesthetic. Any CSS color string. |
width | number | 0.1–1 | 0.6 | Box width as a fraction of the category band width. |
strokeWidth | number | 0.5–5 | 1.5 | Width of the box outline, the median line, and the whiskers in pixels. |
pointSize | number | 1–10 | 2.5 | Radius in pixels of the points drawn beyond the whiskers. |
alpha | number | 0–1 | 0.8 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Vertical Line (Reference)
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
xintercept | number | — | — | X value at which the line is drawn. When omitted, a line is drawn at each value of the column mapped to x. |
lineType | 'solid' | 'dashed' | 'dotted' | — | 'dashed' | Dash pattern of the line. |
color | string (CSS color) | — | '#888888' | Line color used when no column is mapped to the color aesthetic. Any CSS color string. |
strokeWidth | number | 1–5 | 1 | Line width in pixels. |
alpha | number | 0–1 | 0.7 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Horizontal Line (Reference)
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
yintercept | number | — | — | Y value at which the line is drawn. When omitted, a line is drawn at each value of the column mapped to y. |
lineType | 'solid' | 'dashed' | 'dotted' | — | 'dashed' | Dash pattern of the line. |
color | string (CSS color) | — | '#888888' | Line color used when no column is mapped to the color aesthetic. Any CSS color string. |
strokeWidth | number | 1–5 | 1 | Line width in pixels. |
alpha | number | 0–1 | 0.7 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Sloped Line (Reference)
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
slope | number | — | 1 | Slope of the line: the change in y per unit change in x (per millisecond on a date or datetime x axis). |
intercept | number | — | 0 | Y value of the line at x = 0 (at 1970-01-01T00:00:00Z on a date or datetime x axis). |
lineType | 'solid' | 'dashed' | 'dotted' | — | 'dashed' | Dash pattern of the line. |
color | string (CSS color) | — | '#888888' | Line color. Any CSS color string. |
strokeWidth | number | 1–5 | 1 | Line width in pixels. |
alpha | number | 0–1 | 0.7 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Density 2D
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
bandwidth | 'auto' | number | — | 'auto' | Kernel bandwidth as a fraction of the mean of the x and y axis ranges. auto chooses the bandwidth by Scott's rule. The UI offers 0.1 to 2; the API accepts any positive number. |
levels | number | 5–30 | 10 | Approximate number of contour levels. Thresholds are placed at evenly spaced round values from 0 up to the maximum density, so the number drawn can differ from this value. |
colorScale | 'YlOrRd' | 'Blues' | 'Greens' | 'Greys' | 'Purples' | 'Viridis' | 'Plasma' | — | 'YlOrRd' | Sequential palette that maps density to color. |
visualization | 'filled-with-lines' | 'filled-only' | 'contour-only' | — | 'filled-with-lines' | Whether to draw filled regions, contour lines, or both. |
alpha | number | 0–1 | 0.8 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Text (Label)
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
color | string (CSS color) | — | '#333333' | Text color used when no column is mapped to the color aesthetic. Any CSS color string. |
fontSize | number | 6–24 | 11 | Font size in pixels. |
fontWeight | 'normal' | 'bold' | — | 'normal' | Weight of the text. |
textAnchor | 'start' | 'middle' | 'end' | — | 'middle' | Horizontal alignment of the text relative to the point: the text starts at, is centered on, or ends at the point. |
dx | number | -50–50 | 0 | Horizontal offset of the text from the point in pixels. |
dy | number | -50–50 | -8 | Vertical offset of the text from the point in pixels. Negative values move the text up. |
alpha | number | 0–1 | 1 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
Label (Annotation)
| Key | Type | Range | Default | Description |
|---|---|---|---|---|
color | string (CSS color) | — | '#333333' | Text color used when no column is mapped to the color aesthetic. Any CSS color string. |
fontSize | number | 6–24 | 11 | Font size in pixels. |
fontWeight | 'normal' | 'bold' | — | 'normal' | Weight of the text. |
backgroundColor | string (CSS color) | — | '#ffffff' | Background color of the text box. Any CSS color string. |
backgroundAlpha | number | 0–1 | 0.93 | Opacity of the text box background, from 0 (fully transparent) to 1 (fully opaque). |
borderColor | string (CSS color) | — | '#cccccc' | Border color of the text box. Any CSS color string. |
leaderColor | string (CSS color) | — | '#999999' | Color of the leader line from the point to the text box. Any CSS color string. |
padding | number | 0–16 | 4 | Space between the text and the edge of the text box in pixels. |
offsetDistance | number | 10–80 | 30 | Distance from the point to the text box in pixels. |
alpha | number | 0–1 | 1 | Opacity of the layer, from 0 (fully transparent) to 1 (fully opaque). |
複数の layer に異なる固定色を設定する
各系列を個別の layer として追加し、それぞれに geom.defaults.color を設定します。
// layer 1: 実測値(青)
await window.midas.tabs.addGraphLayer(tabId, {
geom: { type: 'line', defaults: { color: '#3366CC' } },
aes: { x: 'date', y: 'actual' }
});
// layer 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' }
});
系列数が動的に変わる場合や、複数グラフでパレット色をそろえたい場合は、この方法を使います。
Stat と Label の連携
layer で stat(Count、Summary、Bin 等)を使用すると、元のカラム値が集約結果に置き換わります。aes.label のカラムマッピングでは変換後のデータから元の値を参照できません。集約値をラベルとして表示するには、aes.label の代わりに geom.defaults.labelContent を設定します。
labelContent は $ プレフィックス付きの変数か列を参照します。stat の出力を表す変数は次のとおりです。
| 変数 | 説明 |
|---|---|
$y | stat 変換後の Y 値(count、mean 等)。position が fill の layer では各 X 位置の値の絶対値合計に対する割合になり、tooltip で format を省略するとパーセント形式で表示されます。label も省略すると % of total が付きます(stat の yScale が density か proportion なら % of total, groups weighted equally)。position が jitter の layer では、ずらす前の値です |
$x | X 値(ビン中心、カテゴリ名)。position が dodge か jitter の layer では、ずらす前の値です |
$n | stat がその点の値の計算に使った観測数です。欠損値は数えません。Count・Bin・Summary・Boxplot などの stat が出力し、Smooth(回帰曲線)は出力しません |
$xmin | ビンの下限(Bin stat・Time Bin stat) |
$xmax | ビンの上限(Bin stat・Time Bin stat) |
$ymin | インターバルの下限 |
$ymax | インターバルの上限 |
$q1 | 第 1 四分位数(Boxplot stat) |
$q3 | 第 3 四分位数(Boxplot stat) |
表の変数のほかに、aesthetic に割り当てた値を表す変数($color、$fill、$alpha、$label など)も指定できます。$label の値は、点が Label に割り当てた列の値を保っていればその値です。stat を使わない layer の点は列の値を保つので、$label を指定すると、その列の値に prefix・suffix を付けたラベルになります。X Mean・X Median・Y Mean の点では、$label の値はその 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 オブジェクトのプロパティ:
| プロパティ | 型 | 説明 |
|---|---|---|
field | string | $ プレフィックス付き変数(上表参照)、またはカラム名かカラム ID。カラム名は大文字小文字を区別せずに解決されます |
format | string | d3-format 書式指定。省略できます。数値の値にだけ適用されます。代表的な書式: .1f(小数 1 桁)、.0%(パーセント、小数なし)、,.0f(桁区切り) |
prefix | string | フォーマット値の前に付加するテキスト |
suffix | string | フォーマット値の後に付加するテキスト |
Graph Builder では、Text・Label の layer のカードの Geometry セクションにある Label Content 欄で labelContent を設定します。欄の Field・Format・Prefix・Suffix は、上の表の field・format・prefix・suffix にそれぞれ対応します。Field で $label 以外の変数か列を選ぶと、Aesthetics セクションの Label に割り当てた列はラベルに使われません。Field を None に戻すと labelContent が解除され、Label に割り当てた列がラベルになります。
Coordinate System
coordinate system はグラフレベルの設定で、tabs.configureGraph または reports.addGraph の coordinates フィールドに指定します。
'cartesian'(デフォルト)— 標準的な Cartesian coordinate system'flipped'— X 軸と Y 軸を入れ替えます。カテゴリラベルが長い横棒グラフで読みやすくなります
GUI では Graph Builder の Coordinate System セクションに対応します。表示例は Custom Graph: 軸の入れ替え を参照してください。
flipped coordinate system での scales.x / scales.y
flipped coordinate system では aes.y のデータが物理 X 軸(横)に、aes.x のデータが物理 Y 軸(縦)に描画されます。scales.x / scales.y の設定は、すべての項目(type、domain、ticks、zoomEnabled、title など)がデータの軸に追従します。scales.x は aes.x のデータの軸(flipped では縦軸)を、scales.y は aes.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 では横軸に表示
}
});
secondary Y axis(scales.y2)は flipped coordinate system では無効になります。
See also
- 高度なグラフ作成 - Custom Graph の使い方とチュートリアル
- Graph Builder タブ - Graph Builder の基本操作
このページの Markdown 版もあります。