MarcelaRobinson_Challege6(FedFunds)

Author

Marcela Robinson

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0     ✔ purrr   1.0.1
✔ tibble  3.1.8     ✔ dplyr   1.1.0
✔ tidyr   1.3.0     ✔ stringr 1.5.0
✔ readr   2.1.3     ✔ forcats 1.0.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(lubridate)

Attaching package: 'lubridate'

The following objects are masked from 'package:base':

    date, intersect, setdiff, union
library(stringr)
library(ggplot2)
install.packages("treemap")
Installing package into '/home/runner/work/_temp/Library'
(as 'lib' is unspecified)
library(treemap)
fedfunds<-read_csv("_data/FedFundsRate.csv")
Rows: 904 Columns: 10
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (10): Year, Month, Day, Federal Funds Target Rate, Federal Funds Upper T...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(fedfunds)

The FedFundsRate data set contains information about federal fund rates from 1954-2017 provided by the Federal Open Markets Committee (FOMC). This data set contains 904 observations and 10 variables, which includes different rates (unemployment, inflation, federal funds target rate), targets (upper, target, and lower), and real GDP.

colnames(fedfunds)
 [1] "Year"                         "Month"                       
 [3] "Day"                          "Federal Funds Target Rate"   
 [5] "Federal Funds Upper Target"   "Federal Funds Lower Target"  
 [7] "Effective Federal Funds Rate" "Real GDP (Percent Change)"   
 [9] "Unemployment Rate"            "Inflation Rate"              

##Combine the day, month and year in one column

fedfunds_date<-fedfunds%>%
  mutate(date = str_c(Year, Month, Day, sep=" "),
         date = ymd(date))%>%
         select(date, "Federal Funds Upper Target","Federal Funds Lower Target", "Effective Federal Funds Rate","Real GDP (Percent Change)","Unemployment Rate","Inflation Rate")

head(fedfunds_date)

For my graph depicting time, I decided to use a a geom_line to show Unemployment Rates over the years. After I initially run the visualization, I noticed there are some values missing from Unemployment Rate. I then decided to use the fill() function to to replace missing values for better visualization.

##Geom_line to show Unemployment Rate over te years

fedfunds_date%>%
  fill(`Unemployment Rate`)%>%
ggplot(aes(date,`Unemployment Rate`))+
  geom_line()+
 theme_classic()+
  labs(title = "Unemployment Rates Over Time", x = "Years", Y = "Unemployment Rate")

For my second graph, I chose a treemap to represent the median values for unemployment rate. I was particularly interested in the rates from 2007 to 2017.

fedfunds%>%
  filter(Year == 2007:2017)%>%
  group_by(Year)%>%
  summarize(Median_Unemployment=median(`Unemployment Rate`))%>%
  treemap(index = "Year", vSize = "Median_Unemployment", type = "index", title= "Unemployment Median Rate Comparison from 2007 to 2017")
Warning: There was 1 warning in `filter()`.
ℹ In argument: `Year == 2007:2017`.
Caused by warning in `Year == 2007:2017`:
! longer object length is not a multiple of shorter object length