Problem 1

For a data set of your choosing, make a faceted plot using the trelliscopejs package. You may make any type of plot; scatter plot, histogram, etc. but, as mentioned in the discussion below, you must explain why you chose this plot and what you are investigating about the variable you are graphing.

The trelliscope plot must include one cognostic measure of your own. Include a description of what it is and what information this measure gives.


Description 2-3 paragraphs.

Describe the data set. Explain the variable you are graphing in your plots and the reason you are investigating with it. Discuss the reason/motivation you chose the variable to facet on, and what insight or trend you are attempting to investigate. Discuss any challenges you had in making the graphs and how you dealt with these challenges. Name at least one cognostic measure (this can include the cognostic you created or be different) the reader could investigate, and explain any insight they might gain from it.


grading: trelliscope plot[25 points], discussion[25 points]


Note: you can add a url directly to the text and it will be active in the html (and word document if you knit to that)

Example: https://www.google.com

If you want to be fancy and make your url active text, you can do this


The Aviation data is a dataset that provides information on the various aviation accidents across the world in terms of fatality. The data was sourced from https://www.kaggle.com/datasets/khsamaha/aviation-accident-database-synopses?rvi=1 and provides information from the US transport accidents database with specific focus on aviation accidents world. The data for this case centered around the aviation accidents that have taken place in the various states in the United States and the territories under the United States.


Two variables are plotted against each other in a scatterplot; these variables are the total uninjured and the total fatal injuries. The former relates to the total number of people that survived an aviation accident without any injuries while the latter relates to the total number of fatalities that resulted from the aviation accident.


# Data
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
AviationData <- read_csv("AviationData.csv")
## Rows: 88889 Columns: 31
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (25): Event.Id, Investigation.Type, Accident.Number, Location, Country,...
## dbl   (5): Number.of.Engines, Total.Fatal.Injuries, Total.Serious.Injuries, ...
## date  (1): Event.Date
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Filtering for data for the United States
AviationData <- AviationData %>% filter(Country == "United States")

#Getting State Initials
library(stringr)
AviationData$State1 <- str_split_fixed(AviationData$Location, ", ", 2)[,2]
AviationData$State2 <- str_split_fixed(AviationData$State1, ", ", 2)[,2]
AviationData$State <- ifelse(AviationData$State2 == "", AviationData$State1, AviationData$State2)

#Variable selection 
AviationData <- AviationData %>% select(State, Investigation.Type, Total.Uninjured, Total.Fatal.Injuries)

#Removing Missing Entries
AviationData <- na.omit(AviationData)
AviationData <- AviationData %>% filter(State != "")


A challenge that arose in the making of the trelliscopejs was the integration of the cognostic measure into the trelliscopejs plot. Despite the plotting using trelliscopejs is fairly straight forward, the integration of the cognostic measure required the nesting of the data, and the use of map_cog and map_plot function whose parameters were a bit challenging to grasp.


The trelliscopejs plot was faceted based in the states and territories of the United States. Further, the cognostic measure that was developed for the trelliscopejs plot was the common investigation type for the accidents as either accident or incident. Understanding the nature of investigation can allow for identification of patterns across states and territories with the same common investigation type.


library(trelliscopejs)
AviationData %>%
  nest(data = !one_of(c("State"))) %>%
  mutate(
    cogs = map_cog(data, ~ tibble(
      common_investigation = cog(tail(names(table(.$Investigation.Type)), 1), desc = "Type of Investigation Normally Conducted")
    )),
    panel = map_plot(data, ~
      qplot(Total.Uninjured, Total.Fatal.Injuries, data = .) + 
        xlab("Total Uninjured") + 
        ylab("Total.Fatal.Injuries") +
        xlim(0, 576) + ylim(0, 230) + theme_bw())) %>%
  trelliscope(name = "Aviation Accidents", nrow = 5, ncol = 5, width = 700, 
              path = "rmarkdown_files", 
              self_contained = TRUE)
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `panel = map_plot(...)`.
## Caused by warning:
## ! `qplot()` was deprecated in ggplot2 3.4.0.