In the preceding chapters, we wrangled change in GDP data and created a tibble to hold that data. We also created data objects to hold our monthly market returns. Below is a peek at those two data frames.
change_in_gdp_wrangled %>%head(3)
# A tibble: 3 × 3
title date percent_change
<chr> <date> <dbl>
1 Change in GDP 2024-04-01 0.03
2 Change in GDP 2024-01-01 0.014
3 Change in GDP 2023-10-01 0.034
Now let’s put them together and explore how they might relate to one another. We chose this use case in order to demonstrate some data visualization capabilities alongside the concept of bucketing or binning data. As usual, we hope the tools here help us in future projects when we have more complex relationships but need fundamental tools.
Here are the packages we will be using in this chapter:
# workhorse packageslibrary(tidyverse)library(tidyquant)library(timetk)library(readxl)library(janitor)# data sourceslibrary(fredr)# vis specificlibrary(gt)library(plotly)library(scales)
Bucketed GDP and Market Returns
Imagine we were asked to hypothesize on the relationship between GDP growth in a quarter and market returns in that quarter? It makes sense that a growing economy leads to or is correlated with a growing stock market and we might expect a positive relationship between these two variables.
Here’s a quick look at whether market returns have been positive or negative during various buckets of GDP growth. No code yet, but we will learn how to build this chart.