Skip to content

Commit

Permalink
Create post-raster_terra.R
Browse files Browse the repository at this point in the history
  • Loading branch information
charliejhadley committed Jun 7, 2024
1 parent c63e2a2 commit 831cff9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions worked-examples/02_10/post-raster_terra.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
library(terra)
library(stars)
library(tidyverse)
library(ggspatial)

# ==== raster ===

alaska_landuse <- rast("data/recoded_alaska_landcover.img")


landuse_types <- read_csv("data/landuse-codes.csv")

colors_landuse <- c("0" = "cadetblue3", "1" = "darkolivegreen", "2" = "darkgreen", "4" = "chocolate", "5" = "antiquewhite")

labels_landuse <- landuse_types %>%
filter(value %in% unique(values(alaska_landuse))) %>%
select(value, label) %>%
deframe()

ggplot() +
layer_spatial(alaska_landuse,
aes(fill = stat(as.character(band1)))) +
scale_fill_manual(values = colors_landuse,
labels = labels_landuse,
name = "Land use types") +
annotation_scale() +
annotation_north_arrow(location = "tl",
pad_x = unit(2, "cm"),
pad_y = unit(1, "cm")) +
theme_void()

0 comments on commit 831cff9

Please sign in to comment.