Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juanchiem/67589df4a48a93dcc8dd01856cc5cd5b to your computer and use it in GitHub Desktop.
Save juanchiem/67589df4a48a93dcc8dd01856cc5cd5b to your computer and use it in GitHub Desktop.
chirps
library(tidyverse)
library(googlesheets4)
link <- "https://docs.google.com/spreadsheets/d/1OXHDK2S2rc5pp-aGKaTwvP8bSdo5faa6YN8QGqGDl7U/edit?usp=sharing"
gs4_deauth()
meteo_eea <- gs4_get(link)
bce22 <- read_sheet(meteo_eea, sheet="2022") %>%
mutate(date = ymd(date))
bce22
# remotes::install_github("ropensci/chirps", build_vignettes = TRUE)
pacman::p_load(chirps, terra, tidyverse)
dates <- c("2022-01-01","2022-12-31")
lonlat_eea <- data.frame(lon = c(-58.305014), lat = c(-37.769968))
lluvias22 <- get_chirps(lonlat_eea, dates, server = "ClimateSERV")
lluvias22
bce22 %>%
left_join(lluvias22) -> bce_full_22
bce_full_22
bce_full_22 %>%
ggplot() +
aes(x=date, y=rain-chirps) +
geom_col()
bce_full_22 %>%
filter(date < ymd("2022-10-01")) %>%
rename(eea=rain) %>%
group_by(date=if_else(day(date) >= 30,
floor_date(date, "20 days"),
floor_date(date, "10 days"))) %>%
summarize_at(vars(eea, chirps), sum) %>%
mutate(month = month(date)) %>%
ungroup %>%
group_by(month) %>%
mutate(decada = row_number()) %>%
ungroup %>%
unite(md, month, decada, sep="_") %>%
pivot_longer(c(eea, chirps)) %>%
ggplot() +
aes(x=md, y=value, fill=name) +
geom_col(alpha=.5, position = "identity") +
coord_flip() +
labs(y="mm por decada")
@juanchiem
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment