Public
Edited
Apr 13, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
color: country_colors[0],
marks: [
Plot.barY(kills_summary, {x: "President", y: deathSelect, fill: "Country"}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
kills_summary = strikes_df
.groupby("President", "Country")
.rollup({
min_civilian_deaths: d => op.sum(d["Minimum civilians reported killed"]),
max_civilian_deaths: d => op.sum(d["Maximum civilians reported killed"]),
min_deaths: d => op.sum(d["Minimum total people killed"]),
max_deaths: d => op.sum(d["Maximum total people killed"])
})
Insert cell
Insert cell
kills_summary_annual = strikes_df
.groupby("year")
.rollup({
min_civilian_deaths: d => op.sum(d["Minimum civilians reported killed"]),
max_civilian_deaths: d => op.sum(d["Maximum civilians reported killed"]),
min_deaths: d => op.sum(d["Minimum total people killed"]),
max_deaths: d => op.sum(d["Maximum total people killed"])
})
.ungroup()
.derive({
avg_civilian_deaths: d => (d.max_civilian_deaths + d.min_civilian_deaths) / 2,
avg_total_deaths: d => (d.max_deaths + d.min_deaths)/ 2
})
.derive({est_combatant_deaths: d => d.avg_total_deaths - d.avg_civilian_deaths})
.derive({combatant_kills_per_civilian: d => d.est_combatant_deaths / d.avg_civilian_deaths})
.orderby("year")
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
x:{
tickFormat: "d"
},
y: {
label: "Combatant to Civilian Kill Ratio"
},
marks:
[
Plot.line(kills_summary_annual, {x: "year", y: "combatant_kills_per_civilian"}),
Plot.ruleY([0]),
Plot.linearRegressionY(kills_summary_annual, {x: "year",
y: "combatant_kills_per_civilian",
stroke: "steelBlue",
ci:0.95})
]
})
Insert cell
Insert cell
Plot.plot({
x: {
tickFormat: "d"
},
y:{
tickFormat: "p"
},
marks:[
Plot.barY(strike_percentages_by_year, {x: "year", y: "percent_strikes_no_civilian_deaths"})
]
}
)
Insert cell
strikes_count_by_year = strikes_df
.groupby("year")
.rollup({
strike_count: d => op.count()
})
Insert cell
strikes_count_no_civilian_deaths = strikes_df
.filter(d => d["Maximum civilians reported killed"] == 0)
.groupby("year")
.rollup({
strike_count_no_civ: d => op.count()
})
Insert cell
strike_percentages_by_year = strikes_count_by_year.join_left(strikes_count_no_civilian_deaths)
.derive({
percent_strikes_no_civilian_deaths: d => d.strike_count_no_civ / d.strike_count
})
.orderby("year")
Insert cell
Insert cell
Insert cell
Plot.plot({
x:{
tickFormat: "d"
},
marks: [
Plot.line(strikes_df, Plot.groupX({y: "sum"},
{x: "year",
y: childDeathVariable // helper that reacts to radio buttons (see appendix)
})),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
land = topojson.feature(land50m, land50m.objects.land)
Insert cell
land50m = FileAttachment("land-50m.json").json()
Insert cell
wb = await FileAttachment("DroneWarsData.xlsx").xlsx({typed: true})
Insert cell
all_strikes = wb.sheet(9, {headers: true})
Insert cell
all_strikes
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
strikes_df = aq.from(all_strikes)
.filter(d => d.President != undefined)
.derive({
date: aq.escape(d => stringToDate(d["Date (MM-DD-YYYY)"]))
})
.derive({
// break up
year: aq.escape(d => d.date.getFullYear()),
month: d => op.month(d.date)
})
Insert cell
Insert cell
function stringToDate(dateString) {
let dateParts = dateString.split("-");

// month is 0-based, so subtract 1
let month = parseInt(dateParts[0]) - 1;
let day = parseInt(dateParts[1]);
let year = parseInt(dateParts[2]);

return new Date(year, month, day);
}
Insert cell
childDeathVariable = { // this variable reacts to the radio buttons for the "Chidlen Killed plot"
if (reportingMethod === "Maximum"){
return("Maximum children reported killed")
} else {
return("Minimum children reported killed")
}
}
Insert cell
Insert cell
country_colors= [ {
scheme: "set1",
type: "categorical",
legend: true
} ,
{
scheme: "set1",
type: "categorical"
}]
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

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