Advertisement
csortu

Recovering of economy after 2008 in EU, Finland, and Hungary

Feb 1st, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 7.32 KB | None | 0 0
  1. library(eurostat)
  2. library(dplyr)
  3. library(ggplot2)
  4. library(directlabels)
  5.  
  6. clean_eurostat_cache()
  7.  
  8. # get all EU region data
  9.  
  10. lp <- get_eurostat_geospatial(output_class = "df", resolution = "20")
  11.  
  12. # Have an EU-wise overview
  13.  
  14. lp.eu <- lp %>% filter(STAT_LEVL_ == 0)
  15. lp.eu$NUTS_ID <- droplevels(lp.eu$NUTS_ID)
  16.  
  17. regions.eu <- levels(lp.eu$NUTS_ID)
  18.  
  19. estat.eu <- get_eurostat('nama_10r_3gdp',
  20.                          filters = list(unit = 'EUR_HAB',
  21.                                         geo = regions.eu),
  22.                          time_format = 'num',
  23.                          type = 'label')
  24.  
  25. estat.eu.sel <- estat.eu %>% filter(!is.na(values) & time>=2008) %>%
  26.   select(region = geo, year = time, GDP = values)  %>%
  27.   group_by(region) %>%
  28.   mutate(GDPP = 100*GDP/GDP[1])
  29.  
  30. # Let's sanitize some country names
  31. levels(estat.eu.sel$region)[grepl("Germany",levels(estat.eu.sel$region))] <- "Germany"
  32. levels(estat.eu.sel$region)[grepl("Macedonia",levels(estat.eu.sel$region))] <- "Macedonia"
  33.  
  34. ggplot(estat.eu.sel,aes(x=year,y=GDP,color=region)) + geom_line() +
  35.   scale_colour_discrete(guide = 'none') +
  36.   expand_limits(x=2015) +
  37.   geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
  38.   ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
  39.   labs(x="Year",y="GDP\n[EUR]")
  40.  
  41. ggplot(estat.eu.sel,aes(x=year,y=GDPP,color=region)) + geom_line() +
  42.   scale_colour_discrete(guide = 'none') +
  43.   expand_limits(x=2015) +
  44.   geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
  45.   ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
  46.   labs(x="Year",y="GDP\n[% of 2008 GDP]") +
  47.   geom_hline(yintercept=100)
  48.  
  49. # see on map the winners and loosers
  50.  
  51. estat.eu.c <- get_eurostat('nama_10r_3gdp',
  52.                            filters = list(unit = 'EUR_HAB',
  53.                                           geo = regions.eu),
  54.                            time_format = 'num')
  55.  
  56. estat.eu.sel.c <- estat.eu.c %>%
  57.   group_by(geo) %>%
  58.   mutate(GDPP = 100*values/values[9]) %>%
  59.   filter(time==2013) %>%
  60.   select(region = geo, GDPP = GDPP)
  61.  
  62. estat.eu.sel.c$success <- cut(estat.eu.sel.c$GDPP,
  63.                               breaks =  c(-Inf,100,Inf),
  64.                               labels = c("failure","success"))
  65.  
  66. lp.eu.gdpp <- left_join(lp.eu %>% filter(lat>36 & long > -12),estat.eu.sel.c,by = c("NUTS_ID" = "region"))
  67.  
  68.  
  69. ggplot(lp.eu.gdpp, aes(x=long,y=lat,group=group,fill=success),color="white") + geom_polygon() +
  70.   ggtitle("Recuperation of GDP in EU\nin 2014 to the level in 2008")
  71.  
  72. ggplot(lp.eu.gdpp, aes(x=long,y=lat,group=group,fill=GDPP),color="white") + geom_polygon() +
  73.   ggtitle("Recuperation of GDP in EU\nin 2014 [% of 2008 GDP]")
  74.  
  75. # Let's check Finland
  76.  
  77.  
  78. lp.fi <- lp %>% filter(grepl('FI',NUTS_ID) & STAT_LEVL_ == 3)
  79. lp.fi$NUTS_ID <- droplevels(lp.fi$NUTS_ID)
  80.  
  81. #ggplot(lp.fi, aes(x=long,y=lat,group=group,fill=NUTS_ID),color="white") + geom_polygon()
  82.  
  83. regions.fi <- levels(lp.fi$NUTS_ID)
  84.  
  85.  
  86. # NUTS 3 level GDP time series in FI
  87.  
  88. estat.fi <- get_eurostat('nama_10r_3gdp',
  89.                          filters = list(unit = 'EUR_HAB',
  90.                                         geo = regions.fi),
  91.                          time_format = 'num',
  92.                          type = 'label')
  93.  
  94. estat.fi.sel <- estat.fi %>% filter(!is.na(values) & time>=2008) %>%
  95.   select(region = geo, year = time, GDP = values)  %>%
  96.   group_by(region) %>%
  97.   mutate(GDPP = 100*GDP/GDP[1])
  98.  
  99.  
  100. ggplot(estat.fi.sel,aes(x=year,y=GDP,color=region)) + geom_line() +
  101.   scale_colour_discrete(guide = 'none') +
  102.   expand_limits(x=2015) +
  103.   geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
  104.   ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
  105.   labs(x="Year",y="GDP\n[EUR]")
  106.  
  107. ggplot(estat.fi.sel,aes(x=year,y=GDPP,color=region)) + geom_line() +
  108.   scale_colour_discrete(guide = 'none') +
  109.   expand_limits(x=2015) +
  110.   geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
  111.   ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
  112.   labs(x="Year",y="GDP\n[% of 2008 GDP]") +
  113.   geom_hline(yintercept=100)
  114.  
  115. # see on map the winners and loosers
  116.  
  117. estat.fi.c <- get_eurostat('nama_10r_3gdp',
  118.                          filters = list(unit = 'EUR_HAB',
  119.                                         geo = regions.fi),
  120.                          time_format = 'num')
  121.  
  122. estat.fi.sel.c <- estat.fi.c %>%
  123.   group_by(geo) %>%
  124.   mutate(GDPP = 100*values/values[9]) %>%
  125.   filter(time==2013) %>%
  126.   select(region = geo, GDPP = GDPP)
  127.  
  128. estat.fi.sel.c$success <- cut(estat.fi.sel.c$GDPP,
  129.                                              breaks =  c(-Inf,100,Inf),
  130.                                              labels = c("failure","success"))
  131.  
  132. lp.fi.gdpp <- left_join(lp.fi,estat.fi.sel.c,by = c("NUTS_ID" = "region"))
  133.  
  134.  
  135. ggplot(lp.fi.gdpp, aes(x=long,y=lat,group=group,fill=success),color="white") + geom_polygon() +
  136.   ggtitle("Recuperation of GDP in Finland\nin 2014 to the level in 2008")
  137.  
  138. ggplot(lp.fi.gdpp, aes(x=long,y=lat,group=group,fill=GDPP),color="white") + geom_polygon() +
  139.   ggtitle("Recuperation of GDP in Finland\nin 2014 [% of 2008 GDP]")
  140.  
  141.  
  142. # Lets repeat for Hungary
  143.  
  144. lp.hu <- lp %>% filter(grepl('HU',NUTS_ID) & STAT_LEVL_ == 3)
  145. lp.hu$NUTS_ID <- droplevels(lp.hu$NUTS_ID)
  146.  
  147. regions.hu <- levels(lp.hu$NUTS_ID)
  148.  
  149.  
  150. # NUTS 3 level GDP time series in HU
  151.  
  152. estat.hu <- get_eurostat('nama_10r_3gdp',
  153.                          filters = list(unit = 'EUR_HAB',
  154.                                         geo = regions.hu),
  155.                          time_format = 'num',
  156.                          type = 'label')
  157.  
  158. estat.hu.sel <- estat.hu %>% filter(!is.na(values) & time>=2008) %>%
  159.   select(region = geo, year = time, GDP = values)  %>%
  160.   group_by(region) %>%
  161.   mutate(GDPP = 100*GDP/GDP[1])
  162.  
  163.  
  164. ggplot(estat.hu.sel,aes(x=year,y=GDP,color=region)) + geom_line() +
  165.   scale_colour_discrete(guide = 'none') +
  166.   expand_limits(x=2015) +
  167.   geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
  168.   ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
  169.   labs(x="Year",y="GDP\n[EUR]")
  170.  
  171. ggplot(estat.hu.sel,aes(x=year,y=GDPP,color=region)) + geom_line() +
  172.   scale_colour_discrete(guide = 'none') +
  173.   expand_limits(x=2015) +
  174.   geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
  175.   ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
  176.   labs(x="Year",y="GDP\n[% of 2008 GDP]") +
  177.   geom_hline(yintercept=100)
  178.  
  179. # see on map the winners and loosers
  180.  
  181. estat.hu.c <- get_eurostat('nama_10r_3gdp',
  182.                            filters = list(unit = 'EUR_HAB',
  183.                                           geo = regions.hu),
  184.                            time_format = 'num')
  185.  
  186. estat.hu.sel.c <- estat.hu.c %>%
  187.   group_by(geo) %>%
  188.   mutate(GDPP = 100*values/values[9]) %>%
  189.   filter(time==2014) %>%
  190.   select(region = geo, GDPP = GDPP)
  191.  
  192. estat.hu.sel.c$success <- cut(estat.hu.sel.c$GDPP,
  193.                               breaks =  c(-Inf,100,Inf),
  194.                               labels = c("failure","success"))
  195.  
  196. lp.hu.gdpp <- left_join(lp.hu,estat.hu.sel.c,by = c("NUTS_ID" = "region"))
  197.  
  198.  
  199. ggplot(lp.hu.gdpp, aes(x=long,y=lat,group=group,fill=success),color="white") + geom_polygon() +
  200.   ggtitle("Recuperation of GDP in Hungary\nin 2014 to the level in 2008")
  201.  
  202. ggplot(lp.hu.gdpp, aes(x=long,y=lat,group=group,fill=GDPP),color="white") + geom_polygon() +
  203.   ggtitle("Recuperation of GDP in Hungary\nin 2014 [% of 2008 GDP]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement