clustJs is a lightweight JavaScript library for high-dimensional data visualization in the
browser. It brings PCA, t-SNE, UMAP, hierarchical clustering, and heatmaps together behind a
simple ES-module API — powered by D3.js. Its hierarchical clustering faithfully reproduces
R's scale()
→ dist()
→ hclust() pipeline,
including the way R handles missing values.
Hierarchical clustering, comparable to R
hclust_plot() is designed so that the same matrix produces the same dendrograms
and leaf order you would get in R:
-
Column standardization like
scale(). Each column is centered and
scaled using only its observed values (mean and sample standard deviation), so
NAs never distort the statistics. Set scaleData: false to cluster raw
values, like hclust(dist(x)) on unscaled data.
-
Distances like
dist(). Pairwise euclidean (or manhattan)
distances are computed from jointly-observed dimensions only, then rescaled by
P / q (total dimensions over observed dimensions) — exactly R's missing-value
correction. If a pair of rows shares no observed dimensions, clustJs refuses to invent a
distance and reports it, rather than silently fabricating one.
-
Linkage like
hclust(). Agglomeration runs on the precomputed
distance matrix (via ml-hclust's agnes) with selectable methods
(complete by default, plus single, average, ward and others) for rows and columns
independently — matching hclust(d, method = ...).
-
Display like
pheatmap(). By default the heatmap shows the scaled
values with rows and columns reordered by the dendrograms; missing cells are rendered
explicitly instead of being dropped. A separate displayData matrix can be supplied
to show raw values while clustering on scaled ones.
Interactive dendrograms
Dendrogram branches are clickable: selecting a branch highlights it down to its leaves and
outlines the corresponding rows or columns in the heatmap. Plot selection re-clusters
and re-renders just that subset (larger cells and labels), and Show all returns to the
full plot. The same selection is available programmatically via the
onSelectionChange callback and the returned node's
hclust.getSelection(), hclust.plotSelection() and
hclust.clearSelection() methods.
Everything runs in the browser
No server, no install: the SDK is a single ES module you can import from a CDN or bundle
yourself. All computation — scaling, distances, clustering, projections — happens
client-side, so your data never leaves the page.
A note on dataset size
clustJs is built for small-to-medium datasets (roughly up to a few thousand rows) — the
typical size where interactive, in-browser exploration shines. Hierarchical clustering is
O(n²) in memory and time, and every cell is rendered as an SVG element, so very large
matrices will get slow. For larger datasets, consider
webR
(R compiled to WebAssembly), which runs R's native hclust() in the browser with
better performance at scale — and since clustJs mirrors R's pipeline, results carry over
directly.
Load a CSV or a built-in dataset, pick a tool on the left, or call the SDK directly from the
console. See the
documentation
for details.