Skip to content

Instantly share code, notes, and snippets.

@juanchiem
Created January 28, 2021 01:09
Show Gist options
  • Save juanchiem/8837d6d9ea84ca79057d12e2cd74dc5f to your computer and use it in GitHub Desktop.
Save juanchiem/8837d6d9ea84ca79057d12e2cd74dc5f to your computer and use it in GitHub Desktop.
library(tidyverse)
coop_dir = tempfile(fileext = ".xls")
dataURL <- "http://coopnecochea.com/web/download/lluvias/Lluvias-2020.xls"
download.file(dataURL, destfile=coop_dir)
total_2020 <- tibble(mes = coop_dir %>% readxl::excel_sheets()) %>%
mutate(data = map(mes, ~readxl::read_excel(coop_dir, sheet = .x) %>%
mutate_all(as.character))) %>%
slice(n()) %>%
unnest(cols = c(data)) %>%
drop_na(Lugar)
total_2020 %>%
select(-TOTAL,-mes) %>%
pivot_longer(cols = c(`ENE`:`DIC`),
names_to = "mes",
values_to = "mm") %>%
mutate(mes = as.factor(mes),
mes = fct_relevel(mes, unique(.$mes)),
mm = as.numeric(mm)) %>%
ggplot()+
aes(x = mes, y=mm)+
geom_col(fill = "steelblue")+
facet_wrap("Lugar")+
cowplot::theme_minimal_hgrid(font_size=9)+
theme(axis.text.x=element_text(angle=60, hjust=1),
plot.subtitle = element_text(face= "italic"))+
labs(title = "Precipitaciones acumuladas 2020",
x = "",
subtitle = "Datos obtenidos de coopnecochea.com\n(@juanchiem)")+
geom_text(data = . %>% group_by(Lugar) %>% summarise(mes = first(mes),
mm = sum(mm)),
aes(label = paste0(mm, "mm"), x = Inf, y = 160, hjust= 1.2),
size =3)
# https://git.io/JtW4W
@juanchiem
Copy link
Author

lluvia

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