<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>GDP Data on R Views</title>
    <link>https://rviews.rstudio.com/tags/gdp-data/</link>
    <description>Recent content in GDP Data on R Views</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 12 Sep 2018 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://rviews.rstudio.com/tags/gdp-data/" rel="self" type="application/rss+xml" />
    
    
    
    
    <item>
      <title>GDP Data via API</title>
      <link>https://rviews.rstudio.com/2018/09/12/gdp-via-api/</link>
      <pubDate>Wed, 12 Sep 2018 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2018/09/12/gdp-via-api/</guid>
      <description>
        


&lt;p&gt;Today, we will look at the GDP data that is released every quarter or so by the Bureau of Economic Analysis &lt;a href=&#34;https://www.bea.gov/data/gdp/gross-domestic-product&#34;&gt;(BEA)&lt;/a&gt;, and get familiar with the BEA API (see the documentation &lt;a href=&#34;https://apps.bea.gov/API/bea_web_service_api_user_guide.htm&#34;&gt;here&lt;/a&gt;). For a primer on GDP in general, BEA publishes this &lt;a href=&#34;https://www.bea.gov/sites/default/files/methodologies/nipa_primer.pdf&#34;&gt;guide&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To access the BEA API, we will need two packages, &lt;code&gt;httr&lt;/code&gt; and &lt;code&gt;jsonlite&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(tidyverse)
library(tidyquant)
library(httr)
library(jsonlite)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We also need to know the API address and parameters to &lt;code&gt;get&lt;/code&gt;. This information can be found in the API documentation referenced above. We supply our API key, the name of the data set (&lt;code&gt;NIPA&lt;/code&gt;), the table name (&lt;code&gt;T10101&lt;/code&gt;, which holds GDP data), and a frequency (&lt;code&gt;Q&lt;/code&gt;, for quarterly).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;&amp;quot;https://apps.bea.gov/api/data/?&amp;amp;UserID=Your-API-Key Here&amp;amp;method=GetData&amp;amp;DataSetName=NIPA&amp;amp;TableName=T10101&amp;amp;Frequency=Q&amp;amp;
Year=ALL&amp;amp;ResultFormat=JSON&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We will pass that URL to the &lt;code&gt;fromJSON()&lt;/code&gt; function of the &lt;code&gt;jsonlite&lt;/code&gt; package to access the API, and include &lt;code&gt;simplifyDataFrame = FALSE&lt;/code&gt; and &lt;code&gt;simplifyMatrix = FALSE&lt;/code&gt; to turn off some of the built-in data helpers.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;key_string &amp;lt;- 
paste(&amp;quot;https://apps.bea.gov/api/data/?&amp;amp;UserID=&amp;quot;, 
      my_api_key,
&amp;quot;&amp;amp;method=GetData&amp;amp;DataSetName=NIPA&amp;amp;TableName=T10101&amp;amp;Frequency=Q&amp;amp;Year=ALL&amp;amp;ResultFormat=JSON&amp;quot;, 
      sep = &amp;quot;&amp;quot;)

bea_gdp_api &amp;lt;- 
  fromJSON(key_string,
  simplifyDataFrame = FALSE, 
  simplifyMatrix = FALSE) 

str(bea_gdp_api, max=3)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;List of 1
 $ BEAAPI:List of 2
  ..$ Request:List of 1
  .. ..$ RequestParam:List of 8
  ..$ Results:List of 5
  .. ..$ Statistic        : chr &amp;quot;NIPA Table&amp;quot;
  .. ..$ UTCProductionTime: chr &amp;quot;2018-09-12T16:30:26.567&amp;quot;
  .. ..$ Dimensions       :List of 9
  .. ..$ Data             :List of 7125
  .. ..$ Notes            :List of 1&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That worked, but the returned data is a monster (remove that &lt;code&gt;max = 3&lt;/code&gt; argument and see what happens)!&lt;/p&gt;
&lt;p&gt;Let’s use &lt;code&gt;pluck()&lt;/code&gt; from the &lt;code&gt;purrr&lt;/code&gt; package to extract the data we want by calling &lt;code&gt;pluck(&amp;quot;BEAAPI&amp;quot;,&amp;quot;Results&amp;quot;,&amp;quot;Data&amp;quot;)&lt;/code&gt;. That command &lt;code&gt;plucks&lt;/code&gt; the list called &lt;code&gt;BEAAPI&lt;/code&gt;, then the list called &lt;code&gt;Results&lt;/code&gt;, then the list called &lt;code&gt;Data&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_api &amp;lt;- 
  fromJSON(&amp;quot;https://apps.bea.gov/api/data/?&amp;amp;UserID=084F6B76-36BE-431F-8F2A-54429DF5E04C&amp;amp;method=GetData&amp;amp;DataSetName=NIPA&amp;amp;TableName=T10101&amp;amp;Frequency=Q&amp;amp;Year=ALL&amp;amp;ResultFormat=JSON&amp;quot;,
  simplifyDataFrame = FALSE, 
  simplifyMatrix = FALSE) %&amp;gt;% 
  pluck(&amp;quot;BEAAPI&amp;quot;,&amp;quot;Results&amp;quot;,&amp;quot;Data&amp;quot;)

str(bea_gdp_api[1])&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;List of 1
 $ :List of 9
  ..$ TableName      : chr &amp;quot;T10101&amp;quot;
  ..$ SeriesCode     : chr &amp;quot;A191RL&amp;quot;
  ..$ LineNumber     : chr &amp;quot;1&amp;quot;
  ..$ LineDescription: chr &amp;quot;Gross domestic product&amp;quot;
  ..$ TimePeriod     : chr &amp;quot;1962Q1&amp;quot;
  ..$ METRIC_NAME    : chr &amp;quot;Fisher Quantity Index&amp;quot;
  ..$ CL_UNIT        : chr &amp;quot;Percent change, annual rate&amp;quot;
  ..$ UNIT_MULT      : chr &amp;quot;0&amp;quot;
  ..$ DataValue      : chr &amp;quot;7.3&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;OK, we’re getting somewhere now - a list of 7125 lists of 9 elements. Looking at those 9 elements, we want the &lt;code&gt;TimePeriod&lt;/code&gt;, the &lt;code&gt;LineDescription&lt;/code&gt;, the &lt;code&gt;DataValue&lt;/code&gt;, and for reasons we’ll see later, the &lt;code&gt;SeriesCode&lt;/code&gt;. So, we want 4 items from each of those 7125 lists, and ideally we would like to convert them to a tibble.&lt;/p&gt;
&lt;p&gt;We can use &lt;code&gt;map_df()&lt;/code&gt; from &lt;code&gt;purrr&lt;/code&gt; to apply the &lt;code&gt;extract()&lt;/code&gt; function from &lt;code&gt;magrittr&lt;/code&gt; and select just the list elements we want, and convert the results to a tibble. By appending &lt;code&gt;_df&lt;/code&gt;, we are telling &lt;code&gt;map&lt;/code&gt; to return a data frame.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_api &amp;lt;- 
  fromJSON(key_string,
  simplifyDataFrame = FALSE, 
  simplifyMatrix = FALSE) %&amp;gt;% 
  pluck(&amp;quot;BEAAPI&amp;quot;,&amp;quot;Results&amp;quot;,&amp;quot;Data&amp;quot;) %&amp;gt;% 
  map_df(magrittr::extract, c(&amp;quot;LineDescription&amp;quot;, &amp;quot;TimePeriod&amp;quot;, 
                              &amp;quot;SeriesCode&amp;quot;, &amp;quot;DataValue&amp;quot;)) 

str(bea_gdp_api)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;Classes &amp;#39;tbl_df&amp;#39;, &amp;#39;tbl&amp;#39; and &amp;#39;data.frame&amp;#39;:   7125 obs. of  4 variables:
 $ LineDescription: chr  &amp;quot;Gross domestic product&amp;quot; &amp;quot;Gross domestic product&amp;quot; &amp;quot;Gross domestic product&amp;quot; &amp;quot;Gross domestic product&amp;quot; ...
 $ TimePeriod     : chr  &amp;quot;1962Q1&amp;quot; &amp;quot;1962Q2&amp;quot; &amp;quot;1962Q3&amp;quot; &amp;quot;1962Q4&amp;quot; ...
 $ SeriesCode     : chr  &amp;quot;A191RL&amp;quot; &amp;quot;A191RL&amp;quot; &amp;quot;A191RL&amp;quot; &amp;quot;A191RL&amp;quot; ...
 $ DataValue      : chr  &amp;quot;7.3&amp;quot; &amp;quot;3.7&amp;quot; &amp;quot;5.0&amp;quot; &amp;quot;1.3&amp;quot; ...&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Much, much better. We now have a tibble, with 4 columns and 7125 rows. Let’s do some cleanup with &lt;code&gt;rename()&lt;/code&gt; for better column names, and then make sure that the &lt;code&gt;percent_change&lt;/code&gt; and &lt;code&gt;quarter&lt;/code&gt; column are in a good format.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_api &amp;lt;- 
  bea_gdp_api %&amp;gt;% 
  group_by(LineDescription) %&amp;gt;% 
  rename(account = LineDescription, 
         quarter = TimePeriod, 
         percent_change = DataValue) %&amp;gt;% 
  mutate(percent_change = as.numeric(percent_change),
         quarter = yq(quarter))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;bea_gdp_api&lt;/code&gt; is now a tibble that holds the quarterly percentage change for each of the GDP accounts used by the BEA, including total GDP change. Let’s take a closer look at each of the accounts whose data we have.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_api %&amp;gt;% 
  count()&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;# A tibble: 21 x 2
# Groups:   account [21]
   account                                                      n
   &amp;lt;chr&amp;gt;                                                    &amp;lt;int&amp;gt;
 1 Durable goods                                              285
 2 Equipment                                                  285
 3 Exports                                                    285
 4 Federal                                                    285
 5 Fixed investment                                           285
 6 Goods                                                      855
 7 Government consumption expenditures and gross investment   285
 8 Gross domestic product                                     285
 9 Gross domestic product, current dollars                    285
10 Gross private domestic investment                          285
# ... with 11 more rows&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We have 21 accounts or groups, including both &lt;code&gt;Gross domestic product&lt;/code&gt; and &lt;code&gt;Gross domestic product, current dollars&lt;/code&gt;. What are the other 19 groups? They are the sub-accounts that comprise GDP. Note that n = 855 for the &lt;code&gt;Goods&lt;/code&gt; account and the &lt;code&gt;Services&lt;/code&gt; account, but we have only 285 quarters of data. That’s because there are three accounts called &lt;code&gt;Goods&lt;/code&gt; and &lt;code&gt;Services&lt;/code&gt; (we’ll look at these three below).&lt;/p&gt;
&lt;p&gt;We can look at the &lt;code&gt;Goods&lt;/code&gt; accounts by &lt;code&gt;SeriesCode&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_api %&amp;gt;% 
  group_by(SeriesCode) %&amp;gt;% 
  slice(1) %&amp;gt;% 
  select(account, SeriesCode) %&amp;gt;% 
  filter(account == &amp;quot;Goods&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;# A tibble: 3 x 2
# Groups:   SeriesCode [3]
  account SeriesCode
  &amp;lt;chr&amp;gt;   &amp;lt;chr&amp;gt;     
1 Goods   A253RL    
2 Goods   A255RL    
3 Goods   DGDSRL    &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is why we grabbed the series codes, too. We need a way to figure out the true account for these three things labeled as &lt;code&gt;Goods&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A web search reveals that &lt;code&gt;A253RL&lt;/code&gt; is for Real Exports of Goods (a third-level account), &lt;code&gt;A255RL&lt;/code&gt; is for Real Imports of Goods (a third-level account), and &lt;code&gt;DGDSRL&lt;/code&gt; is a second-level account and the &lt;code&gt;Goods&lt;/code&gt; component of Real Personal Consumption and Expenditure (PCE).&lt;/p&gt;
&lt;p&gt;Let’s add better account/group names by with &lt;code&gt;case_when()&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_api %&amp;gt;% 
  ungroup() %&amp;gt;%  
  mutate(account = case_when(SeriesCode == &amp;quot;A253RL&amp;quot; ~ &amp;quot;Export Goods&amp;quot;,
                         SeriesCode == &amp;quot;A255RL&amp;quot; ~ &amp;quot;Import Goods&amp;quot;,
                         SeriesCode == &amp;quot;DGDSRL&amp;quot; ~ &amp;quot;Goods&amp;quot;,
                         TRUE ~ .$account)) %&amp;gt;% 
  group_by(account) %&amp;gt;% 
  count()&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;# A tibble: 23 x 2
# Groups:   account [23]
   account                                                      n
   &amp;lt;chr&amp;gt;                                                    &amp;lt;int&amp;gt;
 1 Durable goods                                              285
 2 Equipment                                                  285
 3 Export Goods                                               285
 4 Exports                                                    285
 5 Federal                                                    285
 6 Fixed investment                                           285
 7 Goods                                                      285
 8 Government consumption expenditures and gross investment   285
 9 Gross domestic product                                     285
10 Gross domestic product, current dollars                    285
# ... with 13 more rows&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We repeat that process for &lt;code&gt;Services&lt;/code&gt;, which also had three accounts smooshed into one label.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_api %&amp;gt;% 
  group_by(SeriesCode) %&amp;gt;% 
  slice(1) %&amp;gt;% 
  select(account, SeriesCode) %&amp;gt;% 
  filter(account == &amp;quot;Services&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;# A tibble: 3 x 2
# Groups:   SeriesCode [3]
  account  SeriesCode
  &amp;lt;chr&amp;gt;    &amp;lt;chr&amp;gt;     
1 Services A646RL    
2 Services A656RL    
3 Services DSERRL    &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Similar to with goods, &lt;code&gt;DSERRL&lt;/code&gt; is the services component of PCE and is a second-level account. &lt;code&gt;A656RL&lt;/code&gt; is imports of services (a third-level account), and &lt;code&gt;A646RL&lt;/code&gt; is exports of services.&lt;/p&gt;
&lt;p&gt;Let’s make our changes to both goods and services in the data. I’m also going to replace a few other accounts with shorter names, e.g., I will use “Govt” for “Government consumption expenditures and gross investment”.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_wrangled &amp;lt;- 
  bea_gdp_api %&amp;gt;% 
  ungroup() %&amp;gt;%  
  mutate(account = case_when(SeriesCode == &amp;quot;A253RL&amp;quot; ~ &amp;quot;Export Goods&amp;quot;,
                         SeriesCode == &amp;quot;A255RL&amp;quot; ~ &amp;quot;Import Goods&amp;quot;,
                         SeriesCode == &amp;quot;DGDSRL&amp;quot; ~ &amp;quot;Goods&amp;quot;,
                         SeriesCode == &amp;quot;DSERRL&amp;quot; ~ &amp;quot;Services&amp;quot;,
                         SeriesCode == &amp;quot;A656RL&amp;quot; ~ &amp;quot;Import Services&amp;quot;,
                         SeriesCode == &amp;quot;A646RL&amp;quot; ~ &amp;quot;Export Services&amp;quot;,
                         SeriesCode == &amp;quot;A822RL&amp;quot; ~ &amp;quot;Govt&amp;quot;,
                         SeriesCode == &amp;quot;A006RL&amp;quot; ~ &amp;quot;Investment&amp;quot;,
                         SeriesCode == &amp;quot;DPCERL&amp;quot; ~ &amp;quot;PCE&amp;quot;,
                         TRUE ~ .$account)) %&amp;gt;% 
  group_by(account) %&amp;gt;% 
  select(-SeriesCode)

bea_gdp_wrangled %&amp;gt;% 
  count()&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;# A tibble: 25 x 2
# Groups:   account [25]
   account                    n
   &amp;lt;chr&amp;gt;                  &amp;lt;int&amp;gt;
 1 Durable goods            285
 2 Equipment                285
 3 Export Goods             285
 4 Export Services          285
 5 Exports                  285
 6 Federal                  285
 7 Fixed investment         285
 8 Goods                    285
 9 Govt                     285
10 Gross domestic product   285
# ... with 15 more rows&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We now have 25 accounts, each with 285 observations.&lt;/p&gt;
&lt;p&gt;Let’s move to some visualization and check out how GDP has changed on a quarterly basis since 2008.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_wrangled %&amp;gt;%
filter(quarter &amp;gt; &amp;quot;2008-01-01&amp;quot;) %&amp;gt;% 
filter(account == &amp;quot;Gross domestic product&amp;quot;) %&amp;gt;% 
mutate(col_blue = 
           if_else(percent_change &amp;gt; 0, 
                  percent_change, as.numeric(NA)),
         col_red = 
           if_else(percent_change &amp;lt; 0, 
                  percent_change, as.numeric(NA))) %&amp;gt;%
  ggplot(aes(x = quarter)) +
  geom_col(aes(y = col_red),
               alpha = .85, 
               fill = &amp;quot;pink&amp;quot;, 
               color = &amp;quot;pink&amp;quot;) +
  geom_col(aes(y = col_blue),
               alpha = .85, 
               fill = &amp;quot;cornflowerblue&amp;quot;, 
               color = &amp;quot;cornflowerblue&amp;quot;) +
  ylab(&amp;quot;Quarterly Change (percent)&amp;quot;) +
  scale_x_date(breaks = scales::pretty_breaks(n = 20)) +
  labs(title = &amp;quot;Quarterly GDP Growth&amp;quot;,
       subtitle = &amp;quot;since 2008&amp;quot;,
       x = &amp;quot;&amp;quot;,
       caption = &amp;quot;www.bea.gov/newsreleases/national/gdp/gdpnewsrelease.htm&amp;quot;) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        plot.title = element_text(hjust = 0.5),
        plot.subtitle = element_text(hjust = 0.5),
        plot.caption=element_text(hjust=0))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/post/2018-09-11-gdp-via-api_files/figure-html/unnamed-chunk-13-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;That’s a nice look at GDP quarterly change since 2008, but let’s go a bit deeper and visualize the four top-level components of GDP, which are personal consumption, net exports (or imports and exports), private investment, and government spending. Here is how each changed in Q2 2018.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_wrangled %&amp;gt;% 
  filter((
         account == &amp;quot;PCE&amp;quot; |
         account == &amp;quot;Investment&amp;quot; |
         account == &amp;quot;Exports&amp;quot; |
         account == &amp;quot;Imports&amp;quot; |
         account == &amp;quot;Govt&amp;quot;) &amp;amp;
        quarter == last(quarter)) %&amp;gt;% 
   mutate(col_blue = 
           if_else(percent_change &amp;gt; 0, 
                  percent_change, as.numeric(NA)),
         col_red = 
           if_else(percent_change &amp;lt; 0, 
                  percent_change, as.numeric(NA))) %&amp;gt;%
  ggplot(aes(x = reorder(account, percent_change))) +
  geom_col(aes(y = col_red),
               alpha = .85, 
               fill = &amp;quot;pink&amp;quot;, 
               color = &amp;quot;pink&amp;quot;,
               width = .5) +
  geom_col(aes(y = col_blue),
               alpha = .85, 
               fill = &amp;quot;cornflowerblue&amp;quot;, 
               color = &amp;quot;cornflowerblue&amp;quot;,
               width = .5) +
  labs(title = paste(last(bea_gdp_api$quarter), 
                     &amp;quot;GDP Change&amp;quot;, 
                     sep = &amp;quot; &amp;quot;),
       subtitle = &amp;quot;by account, and total&amp;quot;, 
       x = &amp;quot;account&amp;quot;, 
       y = &amp;quot;change last quarter&amp;quot;) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        plot.title = element_text(hjust = 0.5),
        plot.subtitle = element_text(hjust = 0.5)) +
  scale_y_continuous(breaks = scales::pretty_breaks(n = 10))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/post/2018-09-11-gdp-via-api_files/figure-html/unnamed-chunk-14-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;We can chart how each account has changed over time as well.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;bea_gdp_wrangled %&amp;gt;%
filter(quarter &amp;gt; &amp;quot;2008-01-01&amp;quot;) %&amp;gt;% 
filter(
         account == &amp;quot;PCE&amp;quot; |
         account == &amp;quot;Investment&amp;quot; |
         account == &amp;quot;Exports&amp;quot; |
         account == &amp;quot;Imports&amp;quot; |
         account == &amp;quot;Govt&amp;quot;) %&amp;gt;% 
mutate(col_blue = 
           if_else(percent_change &amp;gt; 0, 
                  percent_change, as.numeric(NA)),
         col_red = 
           if_else(percent_change &amp;lt; 0, 
                  percent_change, as.numeric(NA))) %&amp;gt;%
  ggplot(aes(x = quarter)) +
  geom_col(aes(y = col_red),
               alpha = .85, 
               fill = &amp;quot;pink&amp;quot;, 
               color = &amp;quot;pink&amp;quot;) +
  geom_col(aes(y = col_blue),
               alpha = .85, 
               fill = &amp;quot;cornflowerblue&amp;quot;, 
               color = &amp;quot;cornflowerblue&amp;quot;) +
  ylab(&amp;quot;Quarterly Change (percent)&amp;quot;) +
  scale_x_date(breaks = scales::pretty_breaks(n = 5)) +
  labs(title = &amp;quot;Quarterly GDP Growth&amp;quot;,
       subtitle = &amp;quot;since 2008&amp;quot;,
       x = &amp;quot;&amp;quot;,
       caption = &amp;quot;more here: www.bea.gov/newsreleases/national/gdp/gdpnewsrelease.htm&amp;quot;) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        plot.title = element_text(hjust = 0.5),
        plot.subtitle = element_text(hjust = 0.5),
        plot.caption=element_text(hjust=0)) +
  facet_wrap(~account)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/post/2018-09-11-gdp-via-api_files/figure-html/unnamed-chunk-15-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Note that these charts are showing the percent change of each account on an absolute basis, not how each has contributed to GDP change.&lt;/p&gt;
&lt;p&gt;We will cover that next time and wrap this work to &lt;code&gt;highcharter&lt;/code&gt; to make things interactive. See you then!&lt;/p&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2018/09/12/gdp-via-api/&#39;;&lt;/script&gt;
      </description>
    </item>
    
  </channel>
</rss>
