Public
Edited
Mar 20, 2023
Insert cell
Insert cell
Plot.plot({
x:{round: true,
label: "Percentage of articles per Topic",
labelAnchor: "center",
tickFormat: "%",
domain:[0,0.25]},
grid:true,
marginLeft: 160,
margin:50,
width:800,
y:{label:"Topics"},
marks: [
Plot.barX(percentages, {y:percentages.keys(),x:percentages.values(),fill:Array.from(percentages.keys()),title:titles,sort: {y: "x", reverse: true}}),
Plot.ruleX([0])
],
color: {legend: true}
})
Insert cell
listOfArticles = FileAttachment("list of articles.xlsx").xlsx()
Insert cell
data = listOfArticles.sheet(0,{ headers: true })
Insert cell
topics = data.map(column => column.Topics);
Insert cell
lst = {
let lst=[]
for (var x=0; x<150; x++){
let i=0;
let t = topics[x].split(",")[i];
const size = topics[x].split(",").length;
while (i < size) {
lst.push(t.toUpperCase().trim());
i++;
if (i === size) {
break;
}
t = topics[x].split(",")[i];
}
}
lst.sort()
return lst
}
Insert cell
counts = lst.reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map());
Insert cell
percentages ={
let percentages = new Map();
for (const [key, value] of counts) {
percentages.set(key, (value/lst.length));
}
return percentages
}
Insert cell
titles = Array.from(percentages.values())
Insert cell
{
for(var i=0;i<titles.length;i++){
titles[i]=titles[i]*100;
}
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more