library(sf)
# rast()
# st_read()
library(terra)
library(tidyverse)
# ggplot()
library(tidyterra)
# geom_spatraster()
# hypso.colors
library(ggnewscale)
library(metR)
# geom_text_contour()
library(PNWColors)
# Loading spatial data
mtbDEM <- rast("Data/mtbDEM.tif")
mtbDEM
## class : SpatRaster
## dimensions : 409, 628, 1 (nrow, ncol, nlyr)
## resolution : 5, 5 (x, y)
## extent : 596210.7, 599350.7, 5411132, 5413177 (xmin, xmax, ymin, ymax)
## coord. ref. : WGS 84 / UTM zone 10N (EPSG:32610)
## source : mtbDEM.tif
## name : elev
## min value : 826.4308
## max value : 1689.3694
mtbDEM is a SpatRaster file with 409 rows, 628 columns, and 1 layer. The resolution is 5m x 5m. The CRS projection used is UTM zone 10N. The raster includes elevation data ranging form 826m to 1689m.
# Load hillshade data file
mtbHill <- rast("Data/mtbHill.tif")
mtbHill
## class : SpatRaster
## dimensions : 409, 628, 1 (nrow, ncol, nlyr)
## resolution : 5, 5 (x, y)
## extent : 596210.7, 599350.7, 5411132, 5413177 (xmin, xmax, ymin, ymax)
## coord. ref. : WGS 84 / UTM zone 10N (EPSG:32610)
## source : mtbHill.tif
## name : value
## min value : 0.000000
## max value : 0.999856
mtbHill is a Hillshade spatial raster file with the same dimensions as the elevation data. Its CRS is also UTM zone 10N, so no projection transformations are needed. The hillshade values range from 0 to 1.
# Load shape file for chair lifts
chairs <- st_read("Data/mtbChairLines.shp")
## Reading layer `mtbChairLines' from data source
## `C:\Users\lukeg\OneDrive - Western Washington University\ESCI505_WD\2_Mt_Baker_Map\Data\mtbChairLines.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 8 features and 1 field
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: 596713.7 ymin: 5411451 xmax: 599131.5 ymax: 5412970
## Projected CRS: UTM_Zone_10_Northern_Hemisphere
chairs
## Simple feature collection with 8 features and 1 field
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: 596713.7 ymin: 5411451 xmax: 599131.5 ymax: 5412970
## Projected CRS: UTM_Zone_10_Northern_Hemisphere
## id geometry
## 1 1 LINESTRING (596826 5412970,...
## 2 2 LINESTRING (597260.7 541277...
## 3 3 LINESTRING (597328.6 541275...
## 4 6 LINESTRING (598173.1 541246...
## 5 4 LINESTRING (598194.1 541248...
## 6 5 LINESTRING (598283.2 541250...
## 7 7 LINESTRING (598692.4 541292...
## 8 8 LINESTRING (599131.5 541185...
# Adding "Chair" to each ID for easier labelling in plot
chairs$id <- paste("Chair", as.character(chairs$id))
# Calculating midpoints of each line for label alignment
chair_mid <- st_centroid(chairs)
## Warning: st_centroid assumes attributes are constant over geometries
# Creating color palette from PNWColors for labels and lines
chair_col <- pnw_palette("Sunset2", 8)
The chair lift data is vector data, showing the lines from start to end of each chair lift.
# Loading buildings data
buildings <- read.csv("Data/mtbLodges.csv")
# Saving mtbDEM CRS
utm10nCRS <- st_crs(mtbDEM)
# Converting building data to sf with same CRS as DEM data
bldg_sf <- st_as_sf(buildings, coords = c("X", "Y"), crs = utm10nCRS)
# Mt Baker Map
p1 <- ggplot() +
# Hillshade data
geom_spatraster(data = mtbHill) +
scale_fill_gradientn(colors = gray.colors(100,
start = 0.1,
end = 0.9), guide = "none") +
# Elevation data
new_scale_fill() +
geom_spatraster(data = mtbDEM) +
scale_fill_hypso_c(name = "Elevation (m)",
palette = "colombia_hypso",alpha = 0.6) +
# Contours
geom_spatraster_contour(data = mtbDEM, binwidth = 50, alpha = 0.75) +
geom_text_contour(data = mtbDEM, binwidth = 50,
aes(x = x, y = y, z = elev),
check_overlap = TRUE,
skip = 1,
alpha = 0.75,
size = 2.5) +
# Chair Lifts
geom_sf(data = chairs, aes(color = factor(id)), show.legend = FALSE) +
scale_color_manual(values = chair_col) +
geom_sf_label(data = chair_mid,
aes(label = id, color = factor(id)),
show.legend = FALSE,
alpha = 0.95,
size = 2.75) +
# Buildings
geom_sf(data = bldg_sf, size = 3) +
geom_sf_label(data = bldg_sf, aes(label = id,vjust = -0.4),
alpha = 0.85) +
# Margins and Theme
scale_x_continuous(limits = c(596210.7, 599350.7), expand = c(0, 0)) +
scale_y_continuous(limits = c(5411132, 5413177), expand = c(0, 0)) +
labs(title = "Mt. Baker Map") +
theme_bw() +
theme(panel.grid = element_blank(),
panel.border = element_blank(),
plot.title = element_text(hjust = 0.5),
axis.title = element_blank())
p1