Statistical Fits & Clustering

Regression and LOESS fits with confidence bands, and hierarchical or k-means clustering — built into the engine.

Introduction

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.

Regression & LOESS Fits

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"
});
ParameterDescription
showRegressionFitDraw a parametric regression line
regressionTypeModel for the regression fit (e.g. linear)
showLoessFitDraw a local (LOESS) regression curve
showConfidenceIntervalsShade the confidence band around the fit
confidenceIntervalColorColor of the confidence band
fitLineColorColor of the fitted line

Clustering Heatmaps

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.

Scope

⇧