← Back to list

Tucson Is Full of Terrible Drivers: Using R to Synthesize City of Tucson Open Data

In August 2025, I moved out of my home state and to Tucson, Arizona to begin a new chapter of life with my partner. While the city has much…

Apetty · 2026-06-08 05:17 · 0 claps · 6.9 min read
#library-science #information-science #tucson #public-safety #data-analysis
Open on Medium ↗
Wiki topics: SAF · Safety & Alignment 🔬 · Science · General 📚 · Books & Reading

Tucson Is Full of Terrible Drivers: Using R to Synthesize City of Tucson Open Data

In August 2025, I moved out of my home state and to Tucson, Arizona to begin a new chapter of life with my partner. While the city has much to offer in terms of its natural beauty and city culture, my partner and I have observed an alarming increase in traffic accidents across town. As my partner and I began to see more and more coverage of pedestrian accidents in the news, we began to discuss what is causing these accidents. Where are they most frequently taking place? Does this have to do with driving under the influence? Are nighttime accidents more common than morning ones? There were so many questions to be answered. The steady increase in accidents over the years has certainly caught our attention, as well as the entire city’s, and that is why I decided to use my newfound coding skills to dive into some data and see why Tucson is becoming increasingly dangerous for pedestrians.

This project takes a look at the City of Tucson’s Pedestrian Traffic Accident dataset which was accessed through the City of Tucson’s open data website. This open data site includes thousands of publicly available data sets on city transportation, demographics, safety, economic development, and more. The pedestrian traffic accident data set was curated from 2012–2023, using Tucson Police Department (TPD) data and accident reports. This set is incredibly extensive, including 2,236 rows and 108 features (columns) of relevant data. Included in the data set is basic information such as accident date/time, accident location, and type of offense committed. However, the city did not stop there as they also highlighted additional information such as accident weather, driver sobriety, police response time, accident severity, and much more. The detail included in this data set is incredible, however, the extensive nature of the set limits its’ accessibility. For this reason, I decided to use my data analysis skills in order to create a more accessible, comprehensive look at what this data can tell us about pedestrian accidents in Tucson.

Before diving into the data analysis and visualizations, it’s important to consider the ethical concerns and limitations of the data set I’ve selected and the analysis I’m doing. One of the primary shortcomings of the dataset I’ve selected is that it only contains information on definite pedestrian injuries and deaths. The absence of close calls limits the data as a whole as it only paints a picture of the definite accidents that have occurred throughout town. Including close calls in the data would round out this picture as it would show residents just how frequently careless driving impacts pedestrian safety. Given that this data set was curated from official TPD reports, I went into my analysis assuming that there would be very few ethical concerns. Though, if we were to be skeptical of the data and the data’s source (which we should be), it could be possible that the data includes biases based on the identities of the indiviuals involved in accidents. The potential biases held by TPD officers could interfere with the reports created about the driver and/or pedestrian(s) involved.

The data analysis and visualization process was incredibly interesting, yielding results that I both expected and did not expect at all. As I was analyzing and synthesizing my data, I sought to answer fundamental research questions: who, what, when, where, and how? Given the extensive nature of the data set I was working with, these questions informed which data columns I would look at specifically, as I couldn’t look at them all. My first priority was to produce 3 data visualizations that could give us a look into the overarching themes of pedestrian traffic incidents. I chose to focus my visualizations on the day of week, time of day, and time of year in which accidents occur most frequently.

In order to do this analysis, I primarily utilized the “group_by” and “summarize” functions to find the most frequent results for each category. While this worked well for day of week and time of year, time of day was more difficult to plot as it required me to download the library “stringr” and use the “mutate” function, so that I could convert the times from the data set into strings. By doing so I was able to get rid of the minutes and seconds from my time data, and instead used the first two digits from the string as the hour in which the accident occurred. This made it much easier for my data to be plotted and to be analyzed. The results of my three visualizations, time of day, day of week, and week of year, are as follows:

The first plot, “Pedestrian Traffic Accident Occurrences by Day of Week,” came as a bit of a surprise to me. I had predicted that the weekend, Friday and Saturday specifically, would have the most accidents occuring. I assumed this as traffic is more consistent Friday and Saturday night due to nightlife. While my Friday prediction was correct, Thursday proved to have the most pedestrian accidents of any day of the week, totaling at nearly 380 of the accidents in the data set.

The second plot, “Pedestrian Traffic Accident Occurrences by Time of Day,” yielded less shocking results as I figured most pedestrian traffic accidents happen during rush hour (4–6 PM). Looking at the graph, it is evident that hour 18 (6 PM) has the highest number of pedestrian accidents, totaling at over 250 of the accidents in the data set. 7 and 8 PM closely followed with declining numbers. Despite these accidents occurring during somewhat expected hours, I was intrigued by the overall pattern that this graph displayed. The swooping pattern (up, down, up, down) was really interesting to me, especially the spike in accidents at 7 AM. This graph shows us that traffic accidents become more frequent as the day progresses, spiking during rush hour.

The final plot, “Pedestrian Traffic Accident Occurrences by Week of Year,” was perhaps the most intriguing visualization that I produced throughout this process. As you can see, the graph begins with fairly high numbers in the beginning of the year, then takes a sudden dip from weeks 20–40 before it climbs back up at the end of the year. Interestingly, some of the highest accident numbers seen on this plot are from the week 40 mark on, with the exception of a couple plots towards the beginning of the year. Putting this in context of the city of Tucson, we have a lot of college students from the University of Arizona, as well as a large number of snow birds who travel here during spring. Given the demographic of Tucson in the spring, I was expecting a lot more accidents. It’s interesting to note that the weeks of year in which traffic accidents are worse tends to be when college students and snowbirds are home. This tells me that the root cause of pedestrian traffic accidents is just us Tucsonans, and not college students or snowbirds (as some Tucsonans might assume).

In addition to creating these data visualizations, I did some additional analysis of the data set to provide better context for the graphs I created. Using the “group_by” and “summarize” functions, I chose to look at injury severity, alcohol use, drug use, marijuana use, distracted driving, pedestrian injury severity, violation by driver, hit and run, and lastly, the intersection at which the accident occurred. My analysis yielded unexpected results, showing me that the majority of accidents did NOT include any marijuana, alcohol, or drug use on behalf of the driver. Instead, an overwhelming amount of drivers caused accidents as a result of distracted driving (1,173 distracted drivers vs. 1,073 undistracted). The cause of distraction was not listed, however, I would be willing to bet some good money that it has to do with phone usage. In addition to distracted driving, my analysis of violation by driver showed me that the top mistake drivers are making is failing to yield to pedestrians at a crosswalk. As an interesting side note, I found that Grant was the most frequent street in which accidents occurred. Funny (or maybe not funny) enough, my partner and I live right off of Grant and travel the street frequently via bike and foot.

What makes all this data and the analysis so interesting is the fact that the majority of pedestrian traffic injuries and deaths are not a result of driving under the influence, young college drivers, or weather, but rather failure to pay attention to the road and drive safely. As a new resident of the city, it feels alarming that bad driving has been the cause of so much harm to my city. However, distracted driving is not an end all be all issue. Rather, it’s one that can be fixed by the city through crosswalk specific projects. For example, adding high visibility strips, flashing lights, better lighting around the crosswalk, etc. Additionally, raising awareness of these driving issues with the use of data, such as mine, can hopefully get through to Tucson drivers.

While I am incredibly proud of myself for having turned this monster of a data set into something much more accessible, I do wish I had more time to work on this project. As I mentioned, this data set included more information than I could synthesize in one quarter. Looking towards the future, I hope that I can one day return to this project and look at all the other data I didn’t have time to analyze. Once all the data available has been looked at, I’d love to create an interactive map of the city, plotting different accidents and their details. This intent behind this project is ultimately about raising awareness and educating the public, so I’d love to do as much with this data as I possibly can in hopes that this brings us one step closer to a safer Tucson.


메타데이터
post_id
e97463ee3f09
slug
tucson-is-full-of-terrible-drivers-using-r-to-synthesize-city-of-tucson-open-data-e97463ee3f09
url
https://medium.com/@apetty8/tucson-is-full-of-terrible-drivers-using-r-to-synthesize-city-of-tucson-open-data-e97463ee3f09
canonical_url
https://medium.com/@apetty8/tucson-is-full-of-terrible-drivers-using-r-to-synthesize-city-of-tucson-open-data-e97463ee3f09
author_url
https://medium.com/@apetty8
status
ok
fetched_at
2026-07-15 02:50:08