Published
Edited
May 29, 2021
3 stars
Insert cell
Insert cell
Insert cell
limit = 5 // 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
text = FileAttachment("1000_negative_review_text@1.txt").text()
Insert cell
stopwords = new Set("i,me,my,myself,we,us,our,ours,ourselves,you,your,yours,yourself,yourselves,he,him,his,himself,she,her,hers,herself,it,its,itself,they,them,their,theirs,themselves,what,which,who,whom,whose,this,that,these,those,am,is,are,was,were,be,been,being,have,has,had,having,do,does,did,doing,will,would,should,can,could,ought,i'm,you're,he's,she's,it's,we're,they're,i've,you've,we've,they've,i'd,you'd,he'd,she'd,we'd,they'd,i'll,you'll,he'll,she'll,we'll,they'll,isn't,aren't,wasn't,weren't,hasn't,haven't,hadn't,doesn't,don't,didn't,won't,wouldn't,shan't,shouldn't,can't,cannot,couldn't,mustn't,let's,that's,who's,what's,here's,there's,when's,where's,why's,how's,a,an,the,and,but,if,or,because,as,until,while,of,at,by,for,with,about,against,between,into,through,during,before,after,above,below,to,from,up,upon,down,in,out,on,off,over,under,again,further,then,once,here,there,when,where,why,how,all,any,both,each,few,more,most,other,some,such,no,nor,not,only,own,same,so,than,too,very,say,says,said,shall,1,2,3,4,5,6,7,8,9,10,bit,&,-, food, just, place, one, go get, time".split(","))
Insert cell
count = wordFreq(text)

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 != '' && !stopwords.has(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