Day 6: Frequency`

library(tidyverse)
counties <- read_csv("https://raw.githubusercontent.com/sds-192-intro-fall22/sds-192-public-website-quarto/a8b64e3070ca2543b904d4d92780b09e6062ced6/website/data/nbi_counties.csv")
route_prefixes <- read_csv("https://raw.githubusercontent.com/sds-192-intro-fall22/sds-192-public-website-quarto/a8b64e3070ca2543b904d4d92780b09e6062ced6/website/data/nbi_route_pre.csv")
maintenance <- read_csv("https://raw.githubusercontent.com/sds-192-intro-fall22/sds-192-public-website-quarto/a8b64e3070ca2543b904d4d92780b09e6062ced6/website/data/nbi_maintenance.csv")
kinds <- read_csv("https://raw.githubusercontent.com/sds-192-intro-fall22/sds-192-public-website-quarto/a8b64e3070ca2543b904d4d92780b09e6062ced6/website/data/nbi_kind.csv")

nbi_ma <- read.delim("https://www.fhwa.dot.gov/bridge/nbi/2022/delimited/MA22.txt", sep = ",") |>
  left_join(counties) |>
  left_join(route_prefixes) |>
  left_join(maintenance) |>
  left_join(kinds) |>
  filter(SERVICE_ON_042A == 1) |>
  select(STRUCTURE_NUMBER_008, COUNTY_CODE_003_L, ROUTE_PREFIX_005B_L, MAINTENANCE_021_L, YEAR_BUILT_027, ADT_029, STRUCTURE_KIND_043A_L, STRUCTURAL_EVAL_067, BRIDGE_IMP_COST_094) |>
  mutate(STRUCTURE_KIND_043A_L = 
           case_when(
             STRUCTURE_KIND_043A_L == "Concrete continuous" ~ "Concrete",
             STRUCTURE_KIND_043A_L == "Steel continuous" ~ "Steel",
             STRUCTURE_KIND_043A_L == "Prestressed concrete continuous" ~ "Prestressed concrete",
             TRUE ~ STRUCTURE_KIND_043A_L)) |>
  mutate(BRIDGE_IMP_COST_094 = BRIDGE_IMP_COST_094 * 1000)

rm(counties, kinds, maintenance, route_prefixes)
Question

Check column names and values.

#Check the column names for nbi_ma
Question

Create a plot to visualize the distribution of structural evaluations for bridges in MA. What does the height of the bar represent?

# Plot Here
Question

Facet the previous plot by county

# Plot Here
Question

Create a plot to visualize the frequency of bridges in each county. What does the height of the bar represent?

# Plot Here
Question

Color the previous plot by route prefix, and set the position to dodge. If you finish early, experiment with adjust the plot’s palette. (Refer to ggplot() cheatsheet and lecture slides for help.)

# Plot Here