Published
Edited
Dec 13, 2019
1 fork
1 star
Insert cell
md`# Which US states have the worst drivers?`
Insert cell
md`The dataset for this visualization is from https://github.com/fivethirtyeight/data/blob/master/bad-drivers/bad-drivers.csv`
Insert cell
vegalite = require("@observablehq/vega-lite@0.2")
Insert cell
data = FileAttachment("drivers@1.csv").text()
Insert cell
md`## filter1 = ${filter1}`
Insert cell
viewof filter1 = html`<input type=range min=0 max=30 step=5>`
Insert cell
vegalite({
data: { values: data, format: { type: 'csv' } },
width: 750,
layer: [
{
mark: "bar",
transform: [
{
filter: {
field:
"Number of drivers involved in fatal collisions per billion miles",
gte: filter1
}
}
],
encoding: {
y: {
field: "State",
type: "ordinal",
},
x: {
field: "Number of drivers involved in fatal collisions per billion miles",
type: "quantitative"
},
color: {
field: "Number of drivers involved in fatal collisions per billion miles",
scale: {"range": ["#135421"]}
}
}
}
]
})
Insert cell
md`## filter2 = ${filter2}`
Insert cell
viewof filter2 = html`<input type=range min=20 max=50 step=5>`
Insert cell
vegalite({
data: { values: data, format: { type: 'csv' } },
width: 750,
layer: [
{
mark: "bar",
transform: [
{
filter: {
field:
"Percentage due to Speeding",
gte: filter2
}
}
],
encoding: {
y: {
field: "State",
type: "ordinal",
},
x: {
field: "Percentage due to Speeding",
type: "quantitative"
}
}
}
]
})
Insert cell
md`## filter3 = ${filter3}`
Insert cell
viewof filter3 = html`<input type=range min=0 max=50 step=5>`
Insert cell
vegalite({
data: { values: data, format: { type: 'csv' } },
width: 750,
layer: [
{
mark: "bar",
transform: [
{
filter: {
field:
"Percentage due to Alcohol-Impairment",
gte: filter3
}
}
],
encoding: {
y: {
field: "State",
type: "ordinal",
},
x: {
field: "Percentage due to Alcohol-Impairment",
type: "quantitative"
},
color: {
field: "Percentage due to Alcohol-Impairment",
scale: {"range": ["#ca8861"]}
}
}
}
]
})
Insert cell
md`These data visualizations seek to give us a clearer picture of the behaviors of car drivers in different states in the US. I sought to answer this question using 3 different types of data: the number of drivers involved in fatal collisions per billion miles, the percentage of fatal accidents due to speeding, and the percentage of fatal accidents due to alcohol impairment. These three measures vary a lot across the country, but North Dakota seemed to appear in most visualizations as one of the states with high occurrences of fatal accidents. It has the highest number of drivers involved in fatal collisions per billion miles, tied with South Carolina. DC, Massachusetts and Minnesota seemed to have the fewest number of drivers involved in fatal collisions per billion miles with 5.9, 8.2 and 9.6 respectively. With regards to the fatal collisions which were caused by speeding, Hawaii has the highest percentage with 54, followed by Pennsylvania with a percentage of 50. The state with the lowest percentage of speeding drivers causing accidents were Florida and Tenessee, each with 21. We notice that Massachusetts and Minnesota also have very low percentages of 23 each. With regards to collisions caused by alcohol impairment, Montana has the highest percentage of 44, followed by North Dakota with 42, and South Carolina and Hawaii with 41 each. The states with the lowest percentages turned out to be Utah, Kentucky and Alaska. From this little analysis based on the parameters earlier mentioned, we see that North Dakota turned out to be the state with the highest number of drivers involved in fatal collisions per billion miles, with a high percentage of these drivers being impaired by alcohol. This also applies to South Carolina. Because it’s an irresponsible behavior, alcohol consumption is a good indicator of who’s a bad driver, and we can deduce, solely from these visualizations, that North Dakota and South Carolina have the worst drivers`
Insert cell
md`Getting a dataset to work with was the hardest part of this for me. It took me a while to find a dataset I could actually work with. I used the vega-lite JS library to visualize my data. It was my first time working with it, but it was pretty easy to learn for the first time. The documentations online were very helpful too. Working on this project made me learn new tools for data visualization that I know will be very useful to me. The best part of learning vega-lite was knowing that I can use it to make my data visualizations interactive.`
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