Published
Edited
Jun 2, 2020
2 stars
Insert cell
md`# Joe Rogan Podcast guests
A visualization showing how Joe Rogan expanded from comedians and athletes (fighters), initially, to more diverse guest lineup. I used a combination of Google's Knowledge Graph scripting and manual work to categorize the guests. Data is aggregated by quarters.`
Insert cell
chart = {
var data = d3.csvParse(await FileAttachment("jrePodcastsClassified-2@1.csv").text(), parseData)
for(var i=0; i<data.length; i++) {
var episode = data[i];
var month = episode.date.getMonth() + 1;
var quartal = Math.ceil(month/3);
var monthMap = {
1: 0,
2: 3,
3: 6,
4: 9
}
episode.date = new Date(episode.date.setMonth(monthMap[quartal]));
}
var totals = d3.group(data, d=>d.category)
applyTag(data, 'googled');
applyTag(data, 'description');
applyTag(data, 'guest');
applyByGuest(data);
var color = d3.scaleOrdinal()
.domain(data.columns.slice(1))
.range(d3.schemeCategory10)
var monthlyData = d3.groups(data, d => +d.date)
var categoriesIterator = d3.group(data, d=>d.category).keys();
var template = new Object();
var category = categoriesIterator.next();
while (!category.done) {
template[category.value] = 0;
category = categoriesIterator.next();
}
var cookedData = new Array();
for(var i=monthlyData.length-1; i>=0; i--) {
var categories = JSON.parse(JSON.stringify(template));
var date = new Date(monthlyData[i][0]);
categories.date = date;
var episodes = monthlyData[i][1];
for(var episodeIndex=0; episodeIndex < episodes.length; episodeIndex++) {
var episode = episodes[episodeIndex];
if(categories[episode.category] != null) categories[episode.category]++;
}
cookedData.push(categories);
}
var series = d3.stack()
.keys(Object.getOwnPropertyNames(template))
.offset(d3.stackOffsetExpand)
.order(d3.stackOrderDescending)
(cookedData)
const area = d3.area()
.curve(d3.curveBasis)
.x(d => x(d.data.date))
.y0(d => y(d[0]))
.y1(d => y(d[1]));
const yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(10, "%"))
.call(g => g.select(".domain").remove());
const xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0));
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const x = d3.scaleTime()
.domain(d3.extent(cookedData, d => d.date))
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.range([height - margin.bottom, margin.top]);
svg.append("g")
.selectAll("path")
.data(series)
.join("path")
.attr("fill", ({key}) => color(key))
.attr("d", area)
.append("title")
.text(({key}) => key);
const legendRects = svg.selectAll('rect')
.data(Object.getOwnPropertyNames(template))
.enter()
.append('g')
.attr('transform', (d,i) => `translate(${i*145 + margin.left + 20},${height-margin.bottom-30})`);
legendRects.append('rect')
.attr('fill', d => color(d))
.attr('width', 20)
.attr('height', 20)
.attr('stroke', 'white')
.attr('stroke-width', 1)
legendRects.append('text')
.attr('font-size', 12)
.attr('x', 25)
.attr('y', 14)
.attr('fill', 'white')
.text(d => d);
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);

return svg.node();
}
Insert cell
function color(data) {
return d3.scaleOrdinal()
.domain(data.columns.slice(1))
.range(d3.schemeCategory10);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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