vl.markRect()
.data(aggregatedData3)
.params([
{
name: "intentFilter",
bind: {
input: "select",
options: ["All", ...uniqueIntents],
name: "Intent: "
},
value: "All"
},
{
name: "placeFilter",
bind: {
input: "select",
options: ["All", ...uniquePlaces],
name: "Location: "
},
value: "All"
}
])
.transform([
{ filter: "intentFilter === 'All' || datum.intent === intentFilter" },
{ filter: "placeFilter === 'All' || datum.place === placeFilter" }
])
.encode(
vl.x()
.fieldN("ageGroup")
.title("Age Group")
.sort([
"0-4", "5-9", "10-14", "15-19", "20-24", "25-29", "30-34", "35-39",
"40-44", "45-49", "50-54", "55-59", "60-64", "65-69", "70-74",
"75-79", "80-84", "85-89", "90-94", "95-99"
]),
vl.y().fieldN("place").title("Location").sort("ascending"),
vl.color()
.fieldQ("count")
.title("Number of Deaths")
.scale({ scheme: "reds", unknown: "#c6dbef" }),
vl.tooltip([
{ field: "ageGroup", title: "Age Group" },
{ field: "place", title: "Location" },
{ field: "intent", title: "Intent" },
{ field: "count", title: "Count" }
])
)
.width(900)
.height(500)
.title("Gun Deaths by Age Group and Location (Filterable by Intent and Location)")
.render();