library(haven)
library(dplyr)
library(ggplot2)
library(here)
Fund specific themes for Article IV
Set-ups
We first load a few libraries:
Next we run some code to set up themes and fonts
source(here("utils/theme_and_colors_IMF.R"))
We set up the primary font for charts to Segoe UI .
="Segoe UI" primary_font
Read WEO data
<- read_dta(here("databases/WEOApr2023Pub.dta"))
weo <- weo %>%
weo_us filter(ifscode==111) %>%
select(ifscode, year, lur, pcpi_pch)
#Filtering to only include 1980 data onwards
<- subset(weo_us, year >= 1980) weo_us
After running the set-ups, we are able to plot Article IV standard charts by adding the IMF theme component to ggplot. Let’s compare the layouts using our previous example.
Chart without Article IV format
<- ggplot(data = weo_us, aes(x = lur, y = pcpi_pch)) +
gg geom_point(color=blue,size=2.5) +
labs(title = "US: unemployment and inflation",
x = "Unemployment (percent)", y = "Inflation (percent)")
gg
Chart with Article IV format
<- ggplot(data = weo_us, aes(x = lur, y = pcpi_pch)) +
gg_imf geom_point(color=blue,size=2.5) +
labs(title = "US: unemployment and inflation",
x = "Unemployment (percent)", y = "Inflation (percent)") +
theme_imf()
plot(gg_imf)
This is also a pre-custom setting when using our internal bookr library. In this case, all you would need to do is load the library bookr, and use the same code as before, without explicitly specifying theme imf, as it would be applied automatically.
#Load internal bookr library
library(bookr)
Bookr package has been loaded.
Attaching package: 'bookr'
The following objects are masked _by_ '.GlobalEnv':
A4_colors, A4_colors_bar, rgb2, theme_imf, theme_imf_panel
<- ggplot(data = weo_us, aes(x = lur, y = pcpi_pch)) +
gg geom_point(color=blue,size=2.5) +
labs(title = "US: unemployment and inflation",
x = "Unemployment (percent)", y = "Inflation (percent)")
gg