0. Packages

library(tidyverse) #Data wrangling
library(plotly)    #Interactive plot
library(WDI)       #World Bank data access
library(plyr)      

2. Download data

2.1 GDP_per_capita
gdp_capita <-
  WDI(indicator = "NY.GDP.PCAP.KD", #GDP per capita (constant 2010 US$)
    country = c("CN", "HK"),
    start = 1960, end = 2017)
2.2 GDP_growth rate
gdp_growth <-
  WDI(indicator = "NY.GDP.MKTP.KD.ZG", #GDP per capita growth (annual %)
      country = c("CN", "HK"),
      start = 1960, end = 2017)
2.3 Total Real GDP
gdp_current <-
  WDI(indicator = "NY.GDP.MKTP.CD", #GDP (current US$)
    country = c("CN", "HK"),
    start = 1960, end = 2017)

3. Data wrangling

gdp_capita <- gdp_capita[-2]
colnames(gdp_capita)[1] <- "country"
colnames(gdp_capita)[2] <- "gdp_capita"
gdp_current <- gdp_current[-2]
colnames(gdp_current)[1] <- "country"
colnames(gdp_current)[2] <- "gdp_current"
gdp_growth <- gdp_growth[-2]
colnames(gdp_growth)[1] <- "country"
colnames(gdp_growth)[2] <- "gdp_growth"
comp_gdp <- 
  gdp_current %>% 
  spread("country", "gdp_current") %>% 
  mutate(proportion = HK/CN)

comp_gdp$handover <- ifelse(comp_gdp[1] > 1998, 1, 0)

4. ggplot2

ggplot2: handy visualisation tool for creating static graphs.

Not a main topic of this article.

gdp_capita %>% 
  ggplot(aes(x = year, y = gdp_capita, color = country)) +
  geom_line()
gdp_growth %>% 
  ggplot(aes(x = year, y = gdp_growth, color = country)) +
  geom_line()
gdp_current %>% 
  ggplot(aes(x = year, y = gdp_current, color = country)) +
  geom_line()

5. Interactive plot from plotly package

1) Relative Importance of Hong Kong in total Chinese Economy
comp_gdp_plotly <- 
  comp_gdp %>% 
  select(year, proportion, handover) %>% 
  spread("handover", "proportion")
colnames(comp_gdp_plotly)[c(2, 3)] <- c('before', 'after')

plot_ly(
  comp_gdp_plotly,
  x = ~year,
  y = ~before,
  name = "UK rule",
  type = "bar"
  ) %>% 
  add_trace(y = ~after, name = "Post Handover") %>%
  layout(yaxis = list(tickformat = "%")) %>% 
  layout(title = "Relative Importance of Hong Kong in total Chinese Economy(in 2019 USD)",
         xaxis = list(title = "Year"),
         yaxis = list (title = "HK_GDP / CN_GDP in current USD"))
2) GDP per capita comparison
gdp_capita <- 
  gdp_capita %>% 
  spread("country", "gdp_capita")

plot_ly(gdp_capita,
       x = ~year,
       y = ~CN,
       type = 'bar',
       name = "China",
       marker = list(color = 'red')) %>% 
  add_trace(
    y = ~HK,
    name = "Hong Kong",
    marker = list(color = 'rgb(26, 118, 255')
  ) %>% 
  layout(title = 'GDP per capita comparison: China and Hong Kong (in 2010 USD)',
         yaxis = list (title = "Real GDP per capita"),
         xaxis = list (title = "Year"))
3) Total GDP comparison: China and Hong Kong
gdp_current <-
  gdp_current %>% 
  spread("country", "gdp_current")

plot_ly(gdp_current,
        x = ~year,
        y = ~CN,
        type = 'bar',
        name = "China",
        marker = list(color = 'red')) %>% 
  add_trace(
    y = ~HK,
    name = "Hong Kong",
    marker = list(color = 'rgb(26, 118, 255')
  ) %>% 
  layout(title = 'Total GDP comparison: China and Hong Kong (in 2019 USD)',
         yaxis = list (title = "Real GDP"),
         xaxis = list (title = "Year"))
4) GDP growth comparison
#annual, nominal
gdp_growth <-
  gdp_growth %>% 
  spread("country", "gdp_growth")

plot_ly(gdp_growth, 
        x = ~year, 
        y = ~CN, 
        name = 'China', 
        type = 'scatter', mode = 'lines',
        line = list(color = 'rgb(205, 12, 24)', width = 4)) %>%
  add_trace(y = ~HK, 
            name = 'Hong Kong', 
            line = list(color = 'rgb(22, 96, 167)', width = 4)) %>% 
  layout(title = "Growth rate comparison (annual%, nominal)",
         xaxis = list(title = "Year"),
         yaxis = list (title = "Growth rate")) %>% 
  layout(yaxis = list(ticksuffix = "%"))

To sum up,

  1. Hong Kong’s economic importance in total Chinese economy has been diminishing.
  2. On average, still GDP per capita of Hong Kong vastly outweighs that of China.
  3. Yet, total GDP size of Hong Kong pales in comparison to that of China.
  4. The gap widens as the growth rates of China are greater than those of Hong Kong.