Regression and LOESS fits with confidence bands, and hierarchical or k-means clustering — built into the engine.
CanvasXpress computes several common statistics in the chart itself, so they travel with the figure and work the same from JavaScript, R, Python, notebooks and dashboards. This guide covers trend fits on scatter plots and clustering on heatmaps.
On a 2D scatter plot, set showRegressionFit for a parametric fit (choose the model with regressionType) or showLoessFit for a local regression. Add showConfidenceIntervals to shade the interval; fitLineColor and confidenceIntervalColor set the colors.
var cXFit = new CanvasXpress("canvasFit", fitData, {
graphType: "Scatter2D",
showRegressionFit: true,
regressionType: "linear",
showConfidenceIntervals: true,
fitLineColor: "#0000AA"
});
| Parameter | Description |
|---|---|
showRegressionFit | Draw a parametric regression line |
regressionType | Model for the regression fit (e.g. linear) |
showLoessFit | Draw a local (LOESS) regression curve |
showConfidenceIntervals | Shade the confidence band around the fit |
confidenceIntervalColor | Color of the confidence band |
fitLineColor | Color of the fitted line |
On a heatmap, set samplesClustered and/or variablesClustered to cluster the columns and rows; a dendrogram is drawn alongside the clustered axis. Control the computation with distance and linkage, or switch to k-means with kmeansSmpClusters / kmeansVarClusters (and maxIterations).
{
graphType: "Heatmap",
samplesClustered: true,
variablesClustered: true,
distance: "euclidean",
linkage: "complete"
}
Clustering can also be toggled from the chart’s right-click menu and the Customizer, and the resulting order is saved with the configuration.