library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
data(economics_long)
View(economics_long)
head(economics_long)
## # A tibble: 6 × 4
##   date       variable value  value01
##   <date>     <chr>    <dbl>    <dbl>
## 1 1967-07-01 pce       507. 0       
## 2 1967-08-01 pce       510. 0.000265
## 3 1967-09-01 pce       516. 0.000762
## 4 1967-10-01 pce       512. 0.000471
## 5 1967-11-01 pce       517. 0.000916
## 6 1967-12-01 pce       525. 0.00157
str(economics_long)
## tibble [2,870 × 4] (S3: tbl_df/tbl/data.frame)
##  $ date    : Date[1:2870], format: "1967-07-01" "1967-08-01" ...
##  $ variable: chr [1:2870] "pce" "pce" "pce" "pce" ...
##  $ value   : num [1:2870] 507 510 516 512 517 ...
##  $ value01 : num [1:2870] 0 0.000265 0.000762 0.000471 0.000916 ...

About The Dataset

This dataset was produced from US economic time series data and contains monthly US economic data from 1967 onward. The long version of the economics dataset is used to do the static and interactive graphs.

The variables included in the dataset consist of: 1. The date of the observation in monthly format. 2. The type of economic indicator such as Personal Consumption Expenditures (pce), Population (pop), Personal Savings Rate (psavert), etc. 3. The values of the indicators on each date.

library(paletteer)
## Warning: package 'paletteer' was built under R version 4.4.3
scale_colour_paletteer_d("fishualize::Aluterus_scriptus")
## <ggproto object: Class ScaleDiscrete, Scale, gg>
##     aesthetics: colour
##     axis_order: function
##     break_info: function
##     break_positions: function
##     breaks: waiver
##     call: call
##     clone: function
##     dimension: function
##     drop: TRUE
##     expand: waiver
##     get_breaks: function
##     get_breaks_minor: function
##     get_labels: function
##     get_limits: function
##     get_transformation: function
##     guide: legend
##     is_discrete: function
##     is_empty: function
##     labels: waiver
##     limits: NULL
##     make_sec_title: function
##     make_title: function
##     map: function
##     map_df: function
##     n.breaks.cache: NULL
##     na.translate: TRUE
##     na.value: NA
##     name: waiver
##     palette: function
##     palette.cache: NULL
##     position: left
##     range: environment
##     rescale: function
##     reset: function
##     train: function
##     train_df: function
##     transform: function
##     transform_df: function
##     super:  <ggproto object: Class ScaleDiscrete, Scale, gg>
scale_color_paletteer_d("fishualize::Aluterus_scriptus")
## <ggproto object: Class ScaleDiscrete, Scale, gg>
##     aesthetics: colour
##     axis_order: function
##     break_info: function
##     break_positions: function
##     breaks: waiver
##     call: call
##     clone: function
##     dimension: function
##     drop: TRUE
##     expand: waiver
##     get_breaks: function
##     get_breaks_minor: function
##     get_labels: function
##     get_limits: function
##     get_transformation: function
##     guide: legend
##     is_discrete: function
##     is_empty: function
##     labels: waiver
##     limits: NULL
##     make_sec_title: function
##     make_title: function
##     map: function
##     map_df: function
##     n.breaks.cache: NULL
##     na.translate: TRUE
##     na.value: NA
##     name: waiver
##     palette: function
##     palette.cache: NULL
##     position: left
##     range: environment
##     rescale: function
##     reset: function
##     train: function
##     train_df: function
##     transform: function
##     transform_df: function
##     super:  <ggproto object: Class ScaleDiscrete, Scale, gg>
scale_fill_paletteer_d("fishualize::Aluterus_scriptus")
## <ggproto object: Class ScaleDiscrete, Scale, gg>
##     aesthetics: fill
##     axis_order: function
##     break_info: function
##     break_positions: function
##     breaks: waiver
##     call: call
##     clone: function
##     dimension: function
##     drop: TRUE
##     expand: waiver
##     get_breaks: function
##     get_breaks_minor: function
##     get_labels: function
##     get_limits: function
##     get_transformation: function
##     guide: legend
##     is_discrete: function
##     is_empty: function
##     labels: waiver
##     limits: NULL
##     make_sec_title: function
##     make_title: function
##     map: function
##     map_df: function
##     n.breaks.cache: NULL
##     na.translate: TRUE
##     na.value: NA
##     name: waiver
##     palette: function
##     palette.cache: NULL
##     position: left
##     range: environment
##     rescale: function
##     reset: function
##     train: function
##     train_df: function
##     transform: function
##     transform_df: function
##     super:  <ggproto object: Class ScaleDiscrete, Scale, gg>
paletteer_d("fishualize::Aluterus_scriptus")
## <colors>
## #011C40FF #035AA6FF #05AFF2FF #05C7F2FF #05DBF2FF
library(ggplot2)
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
econ_psavert <- economics_long %>% filter(variable == "psavert")

p <- ggplot(econ_psavert, aes(x = date, y = value)) +
  geom_point(alpha = 1, color = "#05DBF2FF", size = 1) +
  geom_smooth(method = "lm", se = FALSE, color = "#011C40FF") +
  labs(title = "Personal Savings Rate Over Time",
       x = "Year",
       y = "Savings Rate (%)") +
  theme_minimal()

p
## `geom_smooth()` using formula = 'y ~ x'

About the Static Plot

This static plot shows how the personal savings rate (psavert) has changed over time. The transparency of the scatter points are controlled through alpha and size is left more compact for clarity. The regression line highlights the overall trend, which shows that Savings Rate (%) has steadily declined in the US from around 1970 to 2010 on wards.

library(plotly)
## Warning: package 'plotly' was built under R version 4.4.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
interactive_plot <- ggplotly(p)
## `geom_smooth()` using formula = 'y ~ x'
interactive_plot
data(economics_long)
library(gganimate)
## Warning: package 'gganimate' was built under R version 4.4.3
library(scales)
## Warning: package 'scales' was built under R version 4.4.3
eco_anim <- economics_long %>%
  filter(variable %in% c("psavert", "unemploy", "pce", "pop")) %>%  
  ggplot(aes(x = date, y = value, color = variable)) +  
  geom_point() + 
  scale_color_paletteer_d("fishualize::Aluterus_scriptus") +  
  labs(title = 'Month: {frame_time}', 
       x = 'Date', 
       y = 'Value Of Variables') +
  transition_time(date) +  
  ease_aes('linear') +  
  theme_minimal() +  
  facet_wrap(~variable, scales = 'free_y')

eco_anim

a <- animate(eco_anim, fps=5, renderer = av_renderer())

About the Animated Plot

The animation shows the rate of change and volatility from 1970 to 2010 of selected economic variables such as Personal Consumption Expenditures (pce), Population (pop), Personal Savings Rate (psavert), and Number of Unemployed in Thousands (unemploy). It can be said that while consumption expenditure and population increased steadily and comparatively slowly, the savings rate and unemployed rate was much more volatile. Additionally, savings did not increase as drastically as expenditure and population.