library(scales)
library(ggplot2)
library(readr)
##
## Attaching package: 'readr'
## The following object is masked from 'package:scales':
##
## col_factor
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(rmarkdown)
library(magrittr)
library(reticulate)
# libraries:
library(ggplot2)
library(gganimate)
library(gapminder)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble 3.1.1 v stringr 1.4.0
## v tidyr 1.1.3 v forcats 0.5.1
## v purrr 0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x readr::col_factor() masks scales::col_factor()
## x purrr::discard() masks scales::discard()
## x tidyr::extract() masks magrittr::extract()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## x purrr::set_names() masks magrittr::set_names()
library(dygraphs)
library(xts) # To make the convertion data-frame / xts format
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
#Q2
setwd("D:/Jupyter/ACET")
#Reads the csv and puts the data into a created dataframe called habermanData
currentData <- read_csv("Daily_Storage.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## `Water storage area` = col_character(),
## `Total capacity (ML)` = col_double(),
## `Current volume (ML)*` = col_double(),
## `Capacity compared to 24 Sep 2021 (ML)` = col_double(),
## `% full` = col_double(),
## `Recorded rainfall (mm)` = col_double()
## )
head(currentData)
## # A tibble: 6 x 6
## `Water storage a~ `Total capacity~ `Current volume~ `Capacity compar~ `% full`
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Thomson 1068000 886497 1925 83
## 2 Cardinia 286911 207663 71 72.4
## 3 Upper Yarra 200579 184989 1335 92.2
## 4 Sugarloaf 96253 85336 164 88.6
## 5 Silvan 40445 35076 -146 86.7
## 6 Tarago 37580 38067 -45 100
## # ... with 1 more variable: Recorded rainfall (mm) <dbl>
historyData <- read_csv("Historical_Data.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## Year = col_double(),
## January = col_double(),
## February = col_double(),
## March = col_double(),
## April = col_double(),
## May = col_double(),
## June = col_double(),
## July = col_double(),
## August = col_double(),
## September = col_double(),
## October = col_double(),
## November = col_double(),
## December = col_double()
## )
head(historyData)
## # A tibble: 6 x 13
## Year January February March April May June July August September October
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1990 82.4 80.5 77.7 77.8 76.9 77.1 82.6 89.3 93.5 96
## 2 1991 91.1 87.6 84.3 82.0 79.8 79.8 83.0 89.0 96.2 97.0
## 3 1992 93.4 90.9 88.2 85.9 84.3 83.8 83.1 84.6 91.2 95.4
## 4 1993 92.8 90.0 86.9 84.0 81.9 81.5 82.1 84.6 88.8 88.9
## 5 1994 87.5 86.2 84.4 82.9 81.5 81.8 81.7 82.4 83.1 85.1
## 6 1995 81.6 78.9 76.3 76.0 76.2 79.7 83.8 87.1 87.7 89.5
## # ... with 2 more variables: November <dbl>, December <dbl>
data <- historyData %>% pivot_longer(c(`January`, `February`, `March`, `April`, `May`, `June`, `July`, `August`, `September`, `October`, `November`, `December`), names_to = "month", values_to = "storageCapacity")
data$month = factor(data$month, levels = month.name)
head(data)
## # A tibble: 6 x 3
## Year month storageCapacity
## <dbl> <fct> <dbl>
## 1 1990 January 82.4
## 2 1990 February 80.5
## 3 1990 March 77.7
## 4 1990 April 77.8
## 5 1990 May 76.9
## 6 1990 June 77.1
# Make a ggplot, but add frame=year: one image per year
myPlot <- ggplot(data, aes(storageCapacity, month)) +
geom_point() +
scale_x_log10() +
theme_bw() +
# gganimate specific bits:
labs(title = 'Historical Water Storage Levels for Year: {as.integer(frame_time)}', x = 'Storage Capacity in Percentage', y = 'Months') +
transition_time(Year) +
ease_aes('linear')
# Save at gif:
animate(myPlot, duration = 5, fps = 100, width = 600, height = 600, renderer = gifski_renderer())
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).

anim_save("output.gif")