Avalanche Analysis

Interactive Plots
ggiraph
Author

Willa Van Liew

Analysis of Avalanche Accidents and Fatalities in the United States from 1950 to 2022.

Data is available thanks to Colorado Avalanche Information Center (CAIC)

image credit: Matea Nikolina via Unsplash

Background

I have been skiing for a very long time. As a child my father would put on ski movies after a long day on the slopes, most of the movies we would watch would have at least one scene of a professional skier or snowboarder riding down a slope as an avalanche is triggered. Much like quicksand I thought avalanches would be a very big worry as a grew older, but when one skis at a sanctioned ski resort avalanche dangers are slim to none if you are careful.

But I was still curious about them, I wanted to know when they actually occur and how they are triggered. I came across an expansive data set from the Colorado Avalanche Information Center and attempted to answer some of the questions I had.

The Data

The variables present in the data set include copious information about time, location, trigger type, travel mode of those stuck in the avalanche and fatalities.

I was most interested in the basic location, travel mode, fatalities and year.

Have avalanche accidents and fatalities increased over the years?

Show the code
a_year %>%
  ggplot() + 
  geom_line(aes(x = YYYY, y = count, color = type), linewidth = 1) +
  labs(title = "Have Avalanche Accidents and Deaths Increased Over Time?", 
       x = "Year",
       y = "Total Events",
       caption = "Data: Colorado Avalanche Information Center") +
  scale_color_manual(values = c("#E69F00", "#0072B2"),name = "Type",  labels = c("Death","Avalanche"))+
  theme_minimal()

Which states have highest concentration of avalanche accidents?

Show the code
single = paste0(states2$full,"<br>",states2$count," Accident", sep="")
multiple = paste0(states2$full,"<br>",states2$count," Accidents", sep="")

mappedCounts <- states2 %>%
  ggplot(aes(x, y, 
             group = group,
             data_id = full)) +
  geom_polygon_interactive(color = "grey45", 
                           fill = "grey", 
                           aes(tooltip = ifelse(count > 0, ifelse(count > 1, multiple, single), paste0(full,"<br>No Avalanche Accidents", sep="")))) + 
  labs(title="Avalanche Accidents",subtitle = "From April 1951 to May 2022")+
  theme_minimal()+
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank())

graphedCount = states_count %>%
  filter(count >0)%>%
  ggplot()+
  geom_col_interactive(aes(x = fct_reorder(full,count),
                           y = count, 
                           tooltip = ifelse(count > 1, paste0(full,"<br>",count," Accidents", sep=""),paste0(full,"<br>",count," Accident", sep="")), 
                           data_id = full))+
  labs(x = "State", y = "Number of Accidents", caption = "Data: Colorado Avalanche Information Center")+
  theme_minimal()+
  coord_flip()

p = mappedCounts/graphedCount

girafe(ggobj = p, width_svg = 4.5, height_svg = 5.5,options = list(opts_sizing(rescale = TRUE, width = .75)))

Where did these events occur in recent years?

Show the code
g <- list(
  scope = 'usa',
  projection = list(type = 'albers usa'),
  showland = TRUE,
  landcolor = toRGB("gray95"),
  subunitcolor = toRGB("gray85"),
  countrycolor = toRGB("gray85"),
  countrywidth = 0.5,
  subunitwidth = 0.5
)

fig <- plot_geo(recentAccidents, lat = ~lat, lon = ~lon)
fig <- fig %>% add_markers(
    text = ~paste(Location, 
                  paste("State:",state_full), 
                  paste(Killed, PrimaryActivity, "Died"), 
                  Date, sep = "<br />"),
    color = ~factor(Killed), symbol = I("diamond"), size = I(8), hoverinfo = "text"
  )
fig <- fig %>% layout(legend=list(title=list(text='<b> # of Deaths </b>')))
fig <- fig %>% layout(
    title = 'Avalanche Deaths In United States <br /> (From January 2000 to May 2022)',
    geo = g
  )

fig
Show the code
#htmlwidgets::saveWidget(fig, "~/Documents/DS-Masters/CWD/Presentations/img/fig.html", selfcontained=TRUE, libdir = "lib")

Does mode of transportation impact the number of accidents?

Show the code
accidents %>%
  filter(TravelMode %in% c("Foot", "Ski", "Snowboard", "Snowshoe", "Snowmobile")) %>%
  group_by(TravelMode) %>%
  summarize(total_accidents = n(), total_deaths = sum(Killed)) %>%
  ggplot(aes(x = fct_reorder(TravelMode, desc(total_accidents)), y = total_accidents)) +
  geom_col() +
  labs(
    title= "Which Mode of Transportation has the Highest Number of Accidents?",
    x = "Travel Type",
    y = "Number of Avalanches"
  )+
  theme_minimal()

Show the code
travel_type %>%
  ggplot() +
  geom_col(aes(x = fct_reorder(TravelMode, desc(count)), y = count, fill = type), position = "dodge") +
  labs(title = "Distribution of Accidents and Deaths for the Top Modes of Transportation?", 
       x = "Travel Mode", 
       y = "Number of Accidents") +
  scale_fill_manual(values = c("darkgreen", "darkred"), name = "Type", labels = c("Avalanche", "Death"))+
  theme_minimal()

References

Cheng, Joe, Carson Sievert, Barret Schloerke, Winston Chang, Yihui Xie, and Jeff Allen. 2022. Htmltools: Tools for HTML. https://CRAN.R-project.org/package=htmltools.
Di Lorenzo, Paolo. 2022. Usmap: US Maps Including Alaska and Hawaii. https://usmap.dev.
Gohel, David, and Panagiotis Skintzos. 2023. Ggiraph: Make Ggplot2 Graphics Interactive. https://davidgohel.github.io/ggiraph/.
Müller, Kirill, and Hadley Wickham. 2023. Tibble: Simple Data Frames. https://CRAN.R-project.org/package=tibble.
Ooms, Jeroen. 2021. Magick: Advanced Graphics and Image-Processing in r. https://CRAN.R-project.org/package=magick.
Pedersen, Thomas Lin. 2022. Patchwork: The Composer of Plots. https://CRAN.R-project.org/package=patchwork.
Sievert, Carson. 2020. Interactive Web-Based Data Visualization with r, Plotly, and Shiny. Chapman; Hall/CRC. https://plotly-r.com.
Sievert, Carson, Chris Parmer, Toby Hocking, Scott Chamberlain, Karthik Ram, Marianne Corvellec, and Pedro Despouy. 2021. Plotly: Create Interactive Web Graphics via Plotly.js. https://CRAN.R-project.org/package=plotly.
Vaidyanathan, Ramnath, Yihui Xie, JJ Allaire, Joe Cheng, Carson Sievert, and Kenton Russell. 2023. Htmlwidgets: HTML Widgets for r. https://github.com/ramnathv/htmlwidgets.
Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org.
———. 2022a. Forcats: Tools for Working with Categorical Variables (Factors). https://CRAN.R-project.org/package=forcats.
———. 2022b. Stringr: Simple, Consistent Wrappers for Common String Operations. https://CRAN.R-project.org/package=stringr.
———. 2022c. Tidyverse: Easily Install and Load the Tidyverse. https://CRAN.R-project.org/package=tidyverse.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, and Dewey Dunnington. 2022. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://CRAN.R-project.org/package=ggplot2.
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Wickham, Hadley, and Lionel Henry. 2023. Purrr: Functional Programming Tools. https://CRAN.R-project.org/package=purrr.
Wickham, Hadley, Jim Hester, and Jennifer Bryan. 2022. Readr: Read Rectangular Text Data. https://CRAN.R-project.org/package=readr.
Wickham, Hadley, Davis Vaughan, and Maximilian Girlich. 2023. Tidyr: Tidy Messy Data. https://CRAN.R-project.org/package=tidyr.