Module 15c

Author

Sean Lawler

# Load libraries
library(sf)
Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE
library(tmap)

# Set tmap to static mode
tmap_mode("plot")
ℹ tmap mode set to "plot".
# Print working directory and visible files
print(getwd())
[1] "/Users/seanlawler/Downloads/Intro to R/Module 15"
print(list.files())
 [1] "~$dule 15.docx"            "15a_files"                
 [3] "15a.html"                  "15a.qmd"                  
 [5] "15b_files"                 "15b.html"                 
 [7] "15b.qmd"                   "15c.qmd"                  
 [9] "15c.rmarkdown"             "ca_places.zip"            
[11] "gapminderData5.csv"        "GEOG_5680_15a.html"       
[13] "GEOG_5680_15b.html"        "GEOG_5680_15c.html"       
[15] "GEOG_5680_15d.html"        "hsa.csv"                  
[17] "irished.csv"               "LightRail_UTA"            
[19] "LightRail_UTA.zip"         "LightRailStations_UTA"    
[21] "LightRailStations_UTA.zip" "Module 15.docx"           
[23] "Module 15.pdf"             "Module15_abc.qmd"         
[25] "Module15a_files"           "Module15a-b_files"        
[27] "Module15a-b.html"          "Module15a.html"           
[29] "orthodont.csv"             "rs.zip"                   
[31] "rsconnect"                 "slc_tract"                
[33] "slc_tract.zip"             "WNAclimate.csv"           
# Load shapefiles
tracts <- st_read("slc_tract/slc_tract/slc_tract_2015.shp", quiet = TRUE)
lightrail <- st_read("LightRail_UTA/LightRail_UTA/LightRail_UTA.shp", quiet = TRUE)
stations <- st_read("LightRailStations_UTA/LightRailStations_UTA/LightRailStations_UTA.shp", quiet = TRUE)

# Reproject tracts to match light rail CRS
tracts <- st_transform(tracts, st_crs(lightrail))

# Create the map
tm_shape(tracts) +
  tm_fill("density", palette = "Greens", style = "quantile", title = "Popn density") +
  tm_borders("gray80") +
  tm_shape(lightrail) +
  tm_lines(lwd = 2, col = "darkorange") +
  tm_shape(stations) +
  tm_dots(size = 0.25, shape = 21, col = "black", fill = "blue") +
  tm_layout(
    main.title = "Salt Lake County Light Rail and Census Tracts",
    legend.outside = TRUE,
    legend.outside.position = "right"
  )
── tmap v3 code detected ───────────────────────────────────────────────────────
[v3->v4] `tm_fill()`: instead of `style = "quantile"`, use fill.scale =
`tm_scale_intervals()`.
ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to
  'tm_scale_intervals(<HERE>)'
[v3->v4] `tm_fill()`: migrate the argument(s) related to the legend of the
visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'
[v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(main.title = )`
[cols4all] color palettes: use palettes from the R package cols4all. Run
`cols4all::c4a_gui()` to explore them. The old palette name "Greens" is named
"brewer.greens"
Multiple palettes called "greens" found: "brewer.greens", "matplotlib.greens". The first one, "brewer.greens", is returned.