Published
Edited
Jul 23, 2021
1 fork
1 star
Insert cell
Insert cell
Insert cell
limit = 3// number of occurances - min
Insert cell
data = Object.keys(count).filter(d=>count[d] >= limit).map(d => ({name: d, title: d, group: scale(count[d]), value: count[d]}))
Insert cell
scale= d3.scaleLog().domain([limit,d3.max(Object.values(count))])
Insert cell
count = wordFreq(text)

Insert cell
Insert cell
Object.keys(count).length
Insert cell
Insert cell
function wordFreq(string) {
var words = string.toLowerCase().replace(/[.]/g, '').split(/\s/);
var freqMap = {};
words.forEach(function(w) {
if (w != '') {
if (!freqMap[w]) {
freqMap[w] = 0;
}
freqMap[w] += 1;
}
});

return freqMap;
}
Insert cell
width = 600
Insert cell
height = width
Insert cell
format = d3.format(",d")
Insert cell
color = d3.scaleOrdinal(data.map(d => d.group), d3.schemeCategory10)
Insert cell
d3 = require("d3@5")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more