Published
Edited
Aug 4, 2021
1 fork
13 stars
Insert cell
Insert cell
Insert cell
Plot.barX(metaLines, Plot.groupY({x: "count"}, {
y: "raw_character_text",
fill: "raw_character_text"
})).plot({
y: {
domain: topTwentyCharacters
},
color: {
domain: topTwentyCharacters
},
marginLeft: 150
})
Insert cell
Insert cell
Plot.tickX(firstTwentyEpisodes, {
x: "timestamp_in_ms",
y: "raw_character_text",
stroke: "raw_character_text"
}).plot({
y: {
domain: topTwentyCharacters
},
color: {
domain: topTwentyCharacters
},
marginLeft: 150
})
Insert cell
Insert cell
viewof episode = Inputs.range([1, linesByEpisode.length], { step: 1 })
Insert cell
Insert cell
Plot.tickX(episodeLines, {
x: "timestamp_in_ms",
y: "raw_character_text",
stroke: "raw_character_text"
}).plot({ grid: true,
y: { domain: topTwentyCharacters },
color: { domain: topTwentyCharacters },
marginLeft: 150,
})
Insert cell
Plot.tickX(firstTwentyEpisodes, {
x: "timestamp_in_ms",
y: "episode_id",
stroke: "raw_character_text"
}).plot({
marks: [ Plot.frame() ],
grid: true,
facet: {
data: firstTwentyEpisodes,
x: "raw_character_text",
marginTop: 100,
},
fx: {
domain: linesByCharacter.slice(0, 20).map(d => d[0]),
tickRotate: -45
},
color: {
domain: linesByCharacter.slice(0, 20).map(d => d[0])
},
// marginLeft: 150,
width
})
Insert cell
viewof character = Inputs.select(topTwentyCharacters)
Insert cell
Plot.tickX(metaLines.filter(d => d.raw_character_text == character && d.episode_id < 200), {
x: "timestamp_in_ms",
y: "episode_id",
stroke: "raw_character_text"
}).plot({
color: {
domain: topTwentyCharacters
},
y: { grid: true },
marginLeft: 80,
height: 700,
// width
})
Insert cell
Insert cell
episodes = FileAttachment("simpsons_episodes.csv").csv({ typed: true })
Insert cell
episodeMap = new Map(episodes.map(d => [d.id, d]))
Insert cell
linesByEpisode = d3.rollups(metaLines, v => v.length, d => d.episode_id).sort((a,b) => a[0] - b[0])
Insert cell
linesByCharacter = d3.rollups(metaLines, v => v.length, d => d.raw_character_text).sort((a,b) => b[1] - a[1])
Insert cell
topTwentyCharacters = linesByCharacter.slice(0, 21).filter(d => d[0]).map(d => d[0])
Insert cell
firstTwentyEpisodes = metaLines.filter(d => d.episode_id <= 20)
Insert cell
episodeLines = metaLines.filter(d => d.episode_id == episode)
Insert cell
Insert cell
Insert cell
metaLines = FileAttachment("metaLines.csv").csv({ typed: true })
// metaLines = allLines.map(({
// id, episode_id, timestamp_in_ms, speaking_line, raw_character_text, raw_location_text, word_count, normalized_text
// }) => {
// return {
// episode_id,
// timestamp_in_ms,
// speaking_line,
// raw_character_text,
// raw_location_text,
// word_count,
// // normalized_text
// }
// })
Insert cell
Inputs.table(metaLines)
Insert cell
Insert cell
// slimLines = FileAttachment("slimLines@1.csv").csv({ typed: true })
// slimLines = allLines.map(({id, episode_id, timestamp_in_ms, speaking_line, raw_character_text, raw_location_text, word_count, normalized_text}) => {
// return {
// episode_id,
// timestamp_in_ms,
// speaking_line,
// raw_character_text,
// raw_location_text,
// word_count,
// normalized_text
// }
// })
Insert cell
// Inputs.table(slimLines)
Insert cell
Insert cell
// allLines = FileAttachment("simpsons_script_lines.csv").csv({ typed: true })
Insert cell
// Inputs.table(allLines)
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