R Markdown

Assignment 7 Question: Using methods taught in lecture 12, display NJ Funds Covered By Insurance and Balance Less Insurance VS Valuation Date in a single plot for any 3 banks.

Banks Chosen: Wells Fargo, Valley National, and Unity Bank

Loading Data

#Gleason Assignment 7

library(tidyr)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
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(RColorBrewer)
library(Polychrome)
library(hrbrthemes)
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
##       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
##       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
library(gganimate)
## Warning: package 'gganimate' was built under R version 4.3.2
library(gapminder)
## Warning: package 'gapminder' was built under R version 4.3.2
library(magick)
## Warning: package 'magick' was built under R version 4.3.2
## Linking to ImageMagick 6.9.12.98
## Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp
## Disabled features: fontconfig, x11
library(ggrepel)
## Warning: package 'ggrepel' was built under R version 4.3.2
#loading dataset
setwd('C:/Users/Administrator/Box/Fall 2023/Data Vis for Informatics/Assignments/Assignment4')

NJ_GUDPA_Funds_Certificate_List <- read.csv("NJ_GUDPA_Funds_Certificate_List.csv")

setwd('C:/Users/Administrator/Box/Fall 2023/Data Vis for Informatics/Assignments/Assignment 7')

str(NJ_GUDPA_Funds_Certificate_List)
## 'data.frame':    1738 obs. of  9 variables:
##  $ Valuation.Date                    : chr  "12/31/2017" "12/31/2017" "12/31/2017" "12/31/2017" ...
##  $ Institution.Type                  : chr  "BANK" "CREDIT UNION" "BANK" "BANK" ...
##  $ Entity.Name                       : chr  "1st Bank of Sea Isle City" "1st Bergen Federal Credit Union" "1st Colonial Community Bank" "1st Constitution Bank" ...
##  $ X3.Mth.Avg.Bal.of.NJ.Funds..000.s.: int  40859 0 203472 171713 9072 0 34 436336 29909 9970 ...
##  $ NJ.Funds.Cvrd.by.Insurance..000.s.: int  2813 0 11826 7583 2500 0 34 23931 1655 1487 ...
##  $ Balance.Less.Insurance..000.s.    : int  38046 0 191646 164130 6572 0 0 412405 28254 8483 ...
##  $ Required.Collateral..000.s.       : int  20189 0 153560 80281 329 0 0 215434 1413 424 ...
##  $ Collateral.Pledged..000.s.        : int  27784 0 170989 63481 2114 0 0 229267 1779 3273 ...
##  $ Certificate.Type                  : chr  "REGULAR" "LIMITED" "REGULAR" "REGULAR" ...
NJ_GUDPA_Funds_Certificate_List$ValuationDate=as.Date(NJ_GUDPA_Funds_Certificate_List$Valuation.Date,format =  "%m/%d/%Y")


#Selecting Banks
WellsFargo <- NJ_GUDPA_Funds_Certificate_List %>% filter(grepl('Wells Fargo Bank, N.A.', Entity.Name))
ValleyNational <- NJ_GUDPA_Funds_Certificate_List %>% filter(grepl('Valley National Bank', Entity.Name))
Unity <- NJ_GUDPA_Funds_Certificate_List %>% filter(grepl('Unity Bank', Entity.Name))

ThreeBanks<- rbind(Unity, ValleyNational, WellsFargo)

#reviewing variables
summary(ThreeBanks$NJ.Funds.Cvrd.by.Insurance..000.s.)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    5505    7951   41001   32996   46569   67453
summary(ThreeBanks$Balance.Less.Insurance..000.s.)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   83770  157950  656570  732832 1050325 2002929
#making new variable for millions
ThreeBanks$NJ.Funds.Cvrd.by.Insurance.millions <- ThreeBanks$NJ.Funds.Cvrd.by.Insurance..000.s./1000
ThreeBanks$Balance.Less.Insurance.millions <- ThreeBanks$Balance.Less.Insurance..000.s./1000

Creating Chart

balanceless <- "purple2"
fundscovered <- "darkblue"

 #test
 static <-ggplot(ThreeBanks, aes(x=ValuationDate, group = Entity.Name, color = factor(Entity.Name))) +
  geom_line( aes(y=NJ.Funds.Cvrd.by.Insurance.millions), size=1, color=fundscovered) + 
  geom_line( aes(y=Balance.Less.Insurance.millions), size=1, color=balanceless) +
   geom_text(size = 2, aes(label = Entity.Name,
                  nudge_x = 1,
                 y= Balance.Less.Insurance.millions,
                  na.rm = TRUE)) +
    geom_text(size = 2, aes(label = Entity.Name, 
                  nudge_x = 1,
                 y= NJ.Funds.Cvrd.by.Insurance.millions,
                  na.rm = TRUE)) +
    scale_y_continuous(
    
    # Features of the first axis
    name = "NJ Funds Covered by Insurance",
    
    # Add a second axis and specify its features
    sec.axis = sec_axis(~., name="Balances Not Covered by Insurance")
  ) + 
  
  theme_minimal() +
  
  theme(
    axis.title.y = element_text(color = fundscovered, size=12),
    axis.title.y.right = element_text(color = balanceless, size=12)
  ) +
  
  ggtitle("Wells Fargo, Valley National, and United Balances by Coverage Status 
(In Millions)")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning in geom_text(size = 2, aes(label = Entity.Name, nudge_x = 1, y =
## Balance.Less.Insurance.millions, : Ignoring unknown aesthetics: nudge_x and
## na.rm
## Warning in geom_text(size = 2, aes(label = Entity.Name, nudge_x = 1, y =
## NJ.Funds.Cvrd.by.Insurance.millions, : Ignoring unknown aesthetics: nudge_x and
## na.rm
static + transition_reveal(ValuationDate) 
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?