Skip to content

Instantly share code, notes, and snippets.

@jdbcode
Last active May 21, 2021 22:59
Show Gist options
  • Save jdbcode/ff5b8fb452df3256f169f9affcd53e19 to your computer and use it in GitHub Desktop.
Save jdbcode/ff5b8fb452df3256f169f9affcd53e19 to your computer and use it in GitHub Desktop.
[Medium] RStudio Cloud and rgee precip
library(rgee)
library(tidyverse)
library(sf)
ee_Initialize()
nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
terraclimate <- (ee$ImageCollection("IDAHO_EPSCOR/TERRACLIMATE")
$filterDate("2001-01-01", "2002-01-01")
$map(function(x) x$select("pr"))
$toBands()
$rename(sprintf("%02d",1:12)))
ee_nc_rain <- ee_extract(x = terraclimate, y = nc["NAME"], sf = FALSE)
ee_nc_rain %>%
pivot_longer(-NAME, names_to = "month", values_to = "pr") %>%
mutate(month, month=gsub("X", "", month)) %>%
ggplot(aes(x = month, y = pr, group = NAME, color = pr)) +
geom_line(alpha = 0.4) +
xlab("Month") +
ylab("Precipitation (mm)") +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment