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 .
primary_font="Segoe UI"Read WEO data
weo <- read_dta(here("databases/WEOApr2023Pub.dta"))
weo_us <- weo %>%
filter(ifscode==111) %>%
select(ifscode, year, lur, pcpi_pch)
#Filtering to only include 1980 data onwards
weo_us <- subset(weo_us, year >= 1980)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
gg <- ggplot(data = weo_us, aes(x = lur, y = pcpi_pch)) +
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
gg_imf <- ggplot(data = weo_us, aes(x = lur, y = pcpi_pch)) +
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(imfbookr)IMFBookr loaded.SegoeUI
Attaching package: 'imfbookr'
The following objects are masked _by_ '.GlobalEnv':
A4_colors, A4_colors_bar, rgb2, theme_imf, theme_imf_panel
gg <- ggplot(data = weo_us, aes(x = lur, y = pcpi_pch)) +
geom_point(color=blue,size=2.5) +
labs(title = "US: unemployment and inflation",
x = "Unemployment (percent)", y = "Inflation (percent)")
gg
2027 Article IV format
The new IMF 2027 theme features Arial font and black titles/subtitles for a more contemporary appearance.
The good news is, we can adjust our styles by just changing one line of code. To use the 2027 format, simply replace theme_imf() with theme_imf_2027() in your code. That’s the only change needed, everything else works exactly the same.
The chart formatting would then automatically adjust accordingly. For example in the below.
gg_imf_2027 <- ggplot(data = weo_us, aes(x = lur, y = pcpi_pch)) +
geom_point(color=blue,size=2.5) +
labs(title = "US: unemployment and inflation") +
theme_imf_2027()
plot(gg_imf_2027)