Skip to content

Instantly share code, notes, and snippets.

@beatrizmilz
Created January 28, 2021 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beatrizmilz/e17ea2770e60da4a8bbcf6ce06a3c03d to your computer and use it in GitHub Desktop.
Save beatrizmilz/e17ea2770e60da4a8bbcf6ce06a3c03d to your computer and use it in GitHub Desktop.
#' Author: Beatriz Milz
#' Subject: Gráfico do volume armazenado no Sistema Cantareira. Dados da sabesp,
#' disponíveis no pacote mananciais.
library(readr)
library(ggplot2)
library(magrittr)
# Import -----------------------------------------------------------------------
mananciais <-
read_delim(
"https://github.com/beatrizmilz/mananciais/raw/master/inst/extdata/mananciais.csv",
";",
escape_double = FALSE,
locale = locale(decimal_mark = ","),
trim_ws = TRUE
)
# Tidy -------------------------------------------------------------------------
# Base já está arrumada :)
# Visualize --------------------------------------------------------------------
plot_sabesp <-
mananciais %>%
dplyr::filter(sistema == "Cantareira") %>%
dplyr::mutate(data = lubridate::ymd(data)) %>%
ggplot2::ggplot(aes(x = data, y = volume_porcentagem)) +
annotate(
geom = "rect",
xmin = as.Date("2013-01-01"),
xmax = as.Date("2015-12-31"),
ymin = -Inf,
ymax = Inf,
fill = "lightgray",
# colour = "black",
alpha = 0.5,
) +
ggplot2::geom_line(color = "blue", size = 0.5) +
ggplot2::theme_bw() +
ggplot2::labs(x = "Year",
y = "Volume (%) of water \n in System Cantareira") +
geom_vline(
xintercept = as.numeric(as.Date("2013-01-01")),
color = "black",
linetype = "dashed",
size = 0.5
) +
geom_vline(
xintercept = as.numeric(as.Date("2015-12-31")),
color = "black",
linetype = "dashed",
size = 0.5
) +
# geom_hline(
# yintercept = 0,
# color = "black",
# #linetype = "dashed",
# size = 0.4
# ) +
scale_x_date(
date_labels = "%Y",
date_breaks = "2 years",
limits = c(as.Date("2010-01-01"), as.Date("2019-12-31"))
) +
scale_y_continuous(breaks = c(-25, 0, 25, 50, 75, 100)) +
theme(
text = element_text(size = 14),
axis.text.x = element_text(size = 14),
axis.text.y = element_text(size = 14)
)
plot_sabesp
# Export -----------------------------------------------------------------------
plot_sabesp %>% ggsave(filename = "cantareira.png", device = "png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment