John Chavez & Griffin Donnelly

The purpose of this project was to determine a central location based on mainland U.S freight shipments. Point data for freight is in kiloton units and represents an entire metropolitan area. Values represent delivered shipments, outgoing freight was not considered for this project. Certain kiloton measurements were found on the state level, coordinates for their central location were determined using a GoogleMaps API.

This project was a collaboration between John Chavez & Griffin Donnelly. Griffin was the originator of the idea, and John took the lead in writing the code.

# Libraries used: tidyverse, mapdata, plotly, reactable.

read.csv("freight.csv") %>%
  rename(
    Destination=DMS_DEST,
    KTons=`Total.KTons.in.2018`
  ) %>%
  subset(
    str_detect(Destination, "HI|AK|Hawaii|Alaska", negate=T)
  ) %>%
  mutate_geocode(Destination) -> freight

reactable(freight, 
          highlight=TRUE, pagination = FALSE, height = 250, 
          defaultColDef = colDef(format = colFormat(digits = 2)))

Finding the centroids

freight %<>%
    mutate(
      center_x = sum(lon * KTons) / sum(KTons),
      center_y = sum(lat * KTons) / sum(KTons))

Maps

The “Center of Mass” for freight deliveries in the US fell south of the midpoint between Kansas City and St. Louis. Given that the data being used is for deliveries, this location would be the optimal position to place a distribution center.

usa <- geom_polygon(data = map_data("usa"), aes(x=long, y = lat, group = group), fill=rgb(220, 220, 220, max = 255, alpha = 125))

dot <- ggplot() +
  usa + 
  coord_fixed(1.3) +
  geom_point(data=freight, aes(x=center_x, y=center_y), size=5) + 
  geom_point(data=freight, aes(x=lon, y=lat, color=log2(KTons), size=KTons), alpha=0.5) +
  theme(panel.background = element_blank(), legend.position = "none")
  ggplotly(dot)
ggplot(freight) +
    usa + 
    coord_fixed(1.3) +
    geom_segment(
      aes(x=lon, xend=center_x, y=lat, yend=center_y, 
          alpha=KTons), color="#50777E"
    ) +
    theme(panel.background = element_blank(), legend.position = "none")