Created
November 6, 2021 22:04
-
-
Save mikemahoney218/4ae73863861df93722db1229d4c9f17e to your computer and use it in GitHub Desktop.
Code for my map for the 30 Day Map Challenge on November 10, 2021 ("Raster")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(terrainr) | |
library(raster) | |
library(sf) | |
library(ggplot2) | |
library(scico) | |
Marcy <- tmaptools::geocode_OSM("Mount Marcy") | |
Marcy <- st_as_sf(as.data.frame(t(as.data.frame(Marcy$coords))), coords = c("x", "y"), crs = 4326) | |
site_bbox <- set_bbox_side_length(Marcy, 10, "km") | |
site_tiles <- get_tiles(site_bbox, | |
services = c("elevation", "contours")) | |
elevation <- raster(merge_rasters(site_tiles$elevation)) | |
contours <- stack(merge_rasters(site_tiles$contours)) | |
contour_stack <- stack(elevation, contours) | |
contour_df <- as.data.frame(contour_stack, xy = TRUE) | |
names(contour_df) <- c("x", "y", "z", "r", "g", "b", "a") # longitude, latitude, elevation, red, green, blue, alpha | |
contour_lines <- contour_df[contour_df$a != 0, ] | |
ggplot(data = contour_lines)+ | |
geom_raster(mapping = aes(x, y, fill = z))+ | |
theme_void()+ | |
theme(plot.background = element_rect(fill="grey5", color = NA), | |
plot.title = element_text(color="white"), | |
legend.position = "none", | |
plot.margin = margin(0, 0, 0, 0, "cm"))+ | |
coord_sf(crs = 4326)+ | |
scale_fill_scico(palette="vikO", direction = 1) | |
ggsave("20211110.png", height = 14, width = 13, dpi = 300) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment