Exercise 26: Mississippi River Mapping

ESS 330 - Quantitative Reasoning

# set up
library(terra)
Warning: package 'terra' was built under R version 4.4.3
terra 1.8.42
library(ggpubr)
Warning: package 'ggpubr' was built under R version 4.4.3
Loading required package: ggplot2

Attaching package: 'ggpubr'
The following object is masked from 'package:terra':

    rotate
library(ggplot2)

url <- 'https://raw.githubusercontent.com/mikejohnson51/csu-ess-330/refs/heads/main/resources/foco-elev-cm.tif'
vsi_url <- paste0("/vsicurl/", url)

elev_cm <- rast(vsi_url)
elev_ft <- elev_cm * 0.0328084
elev_df <- values(elev_ft, dataframe = TRUE)
gg_density <- ggdensity(elev_df, 
                        x = names(elev_df)[1], 
                        fill = "#69b3a2", 
                        color = "#1f2d36",
                        add = "mean", rug = TRUE) +
  labs(title = "Elevation Density in Feet",
       x = "Elevation (feet)",
       y = "Density") +
  theme_minimal()
Warning: `geom_vline()`: Ignoring `mapping` because `xintercept` was provided.
Warning: `geom_vline()`: Ignoring `data` because `xintercept` was provided.
print(gg_density)

ggsave("../images/elevation_density_plot.png", gg_density, width = 8, height = 6)