Public
Edited
Feb 15, 2024
Insert cell
Insert cell
character_url = "https://pudding.cool/2017/03/film-dialogue/character_list5.csv"
Insert cell
Insert cell
character = aq.loadCSV(character_url)
Insert cell
character1 = d3.csv(character_url, d3.autoTypeype)
Insert cell
Inputs.table(character)
Insert cell
Insert cell
data = aq.from(character)
//select the derired 3 columns
.select("script_id", "gender", "words")
//Group By
.groupby("script_id", "gender")
//Rollup and sum words
.rollup({totalwords: aq.op.sum("words") })
//Group By script_id
.groupby("script_id")
//PIVOT with key = gender and value = totalwords
.pivot("gender", "totalwords")
//DERIVE
.derive({
gratio: (d) => d.f / (d.f + d.m)
})
Insert cell
Inputs.table(data, {width: 500})
Insert cell
Insert cell
Plot.frame()
Insert cell
Plot.plot({
height: 100,
marks: [Plot.dot(data, { x: "gratio", opacity: 0.05, r: 20 })]
})
Insert cell
Plot.plot({
height: 500,
marks: [
Plot.dot(
data,
Plot.dodgeY({ x: "gratio", fill: "gratio", r: 2.5, anchor: "top" })
)
]
})
Insert cell
Insert cell
data2 = aq. from(data)
.derive({ gratio2: (d) => aq.op.round(d.gratio *100)/100})
.groupby("gratio2")
.derive({rRank: aq.op.rank()})
Insert cell
Inputs.table(data2, {width: 500})
Insert cell
Insert cell
Plot.plot({
title: "Filmy Dialogues are too male",
height: 500,
width: width,
//reverse y axis to flip the chart and anchor it from top
y: {reverse: true, axis: null },
//color: to color you need to define the color scheme and the type of data
color: { range: ["blue", "white", "red"], type: "diverging", pivot: 0.5 },
marks: [
Plot.dot(data2, {x: "gratio2", fill: "gratio2", y:"rRank"}),
Plot.dot(data2,
Plot.pointer ({x: "gratio2", y:"rRank", fill: "pink", r:4})),
Plot.tip(data2,
Plot.pointer({
x: "gRatio2",
y: "rRank",
channels: { movie: "script_id" }
}))
]
})
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