setwd("~/Desktop/Hopkins/forested landscapes")
# Load the terra library
library(terra)
## terra 1.8.80
library(ggplot2)
library(tidyterra)
##
## Attaching package: 'tidyterra'
## The following object is masked from 'package:stats':
##
## filter
# Define the file path to your GeoTIFF file on the Mac desktop
file_path <- "Fernow_CanopyHeight.tif"
# Import the raster data into R using the rast() function
# The 'rast' function is used for single or multi-band rasters
my_raster <- rast(file_path)
# Plot the GeoTIFF file
# The plot() function will display the raster data
plot(my_raster)

ggplot() +
geom_spatraster(data = my_raster) +
scale_fill_viridis_c(na.value = "transparent", name = "Value") + # Customize fill scale and legend title
labs(title = "Canopy Height Model for WV Field Area",
x = "Longitude",
y = "Latitude") +
theme_minimal() +
coord_sf()
## <SpatRaster> resampled to 500908 cells.
