Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(eurostat)
- library(dplyr)
- library(ggplot2)
- library(directlabels)
- clean_eurostat_cache()
- # get all EU region data
- lp <- get_eurostat_geospatial(output_class = "df", resolution = "20")
- # Have an EU-wise overview
- lp.eu <- lp %>% filter(STAT_LEVL_ == 0)
- lp.eu$NUTS_ID <- droplevels(lp.eu$NUTS_ID)
- regions.eu <- levels(lp.eu$NUTS_ID)
- estat.eu <- get_eurostat('nama_10r_3gdp',
- filters = list(unit = 'EUR_HAB',
- geo = regions.eu),
- time_format = 'num',
- type = 'label')
- estat.eu.sel <- estat.eu %>% filter(!is.na(values) & time>=2008) %>%
- select(region = geo, year = time, GDP = values) %>%
- group_by(region) %>%
- mutate(GDPP = 100*GDP/GDP[1])
- # Let's sanitize some country names
- levels(estat.eu.sel$region)[grepl("Germany",levels(estat.eu.sel$region))] <- "Germany"
- levels(estat.eu.sel$region)[grepl("Macedonia",levels(estat.eu.sel$region))] <- "Macedonia"
- ggplot(estat.eu.sel,aes(x=year,y=GDP,color=region)) + geom_line() +
- scale_colour_discrete(guide = 'none') +
- expand_limits(x=2015) +
- geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
- ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
- labs(x="Year",y="GDP\n[EUR]")
- ggplot(estat.eu.sel,aes(x=year,y=GDPP,color=region)) + geom_line() +
- scale_colour_discrete(guide = 'none') +
- expand_limits(x=2015) +
- geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
- ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
- labs(x="Year",y="GDP\n[% of 2008 GDP]") +
- geom_hline(yintercept=100)
- # see on map the winners and loosers
- estat.eu.c <- get_eurostat('nama_10r_3gdp',
- filters = list(unit = 'EUR_HAB',
- geo = regions.eu),
- time_format = 'num')
- estat.eu.sel.c <- estat.eu.c %>%
- group_by(geo) %>%
- mutate(GDPP = 100*values/values[9]) %>%
- filter(time==2013) %>%
- select(region = geo, GDPP = GDPP)
- estat.eu.sel.c$success <- cut(estat.eu.sel.c$GDPP,
- breaks = c(-Inf,100,Inf),
- labels = c("failure","success"))
- lp.eu.gdpp <- left_join(lp.eu %>% filter(lat>36 & long > -12),estat.eu.sel.c,by = c("NUTS_ID" = "region"))
- ggplot(lp.eu.gdpp, aes(x=long,y=lat,group=group,fill=success),color="white") + geom_polygon() +
- ggtitle("Recuperation of GDP in EU\nin 2014 to the level in 2008")
- ggplot(lp.eu.gdpp, aes(x=long,y=lat,group=group,fill=GDPP),color="white") + geom_polygon() +
- ggtitle("Recuperation of GDP in EU\nin 2014 [% of 2008 GDP]")
- # Let's check Finland
- lp.fi <- lp %>% filter(grepl('FI',NUTS_ID) & STAT_LEVL_ == 3)
- lp.fi$NUTS_ID <- droplevels(lp.fi$NUTS_ID)
- #ggplot(lp.fi, aes(x=long,y=lat,group=group,fill=NUTS_ID),color="white") + geom_polygon()
- regions.fi <- levels(lp.fi$NUTS_ID)
- # NUTS 3 level GDP time series in FI
- estat.fi <- get_eurostat('nama_10r_3gdp',
- filters = list(unit = 'EUR_HAB',
- geo = regions.fi),
- time_format = 'num',
- type = 'label')
- estat.fi.sel <- estat.fi %>% filter(!is.na(values) & time>=2008) %>%
- select(region = geo, year = time, GDP = values) %>%
- group_by(region) %>%
- mutate(GDPP = 100*GDP/GDP[1])
- ggplot(estat.fi.sel,aes(x=year,y=GDP,color=region)) + geom_line() +
- scale_colour_discrete(guide = 'none') +
- expand_limits(x=2015) +
- geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
- ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
- labs(x="Year",y="GDP\n[EUR]")
- ggplot(estat.fi.sel,aes(x=year,y=GDPP,color=region)) + geom_line() +
- scale_colour_discrete(guide = 'none') +
- expand_limits(x=2015) +
- geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
- ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
- labs(x="Year",y="GDP\n[% of 2008 GDP]") +
- geom_hline(yintercept=100)
- # see on map the winners and loosers
- estat.fi.c <- get_eurostat('nama_10r_3gdp',
- filters = list(unit = 'EUR_HAB',
- geo = regions.fi),
- time_format = 'num')
- estat.fi.sel.c <- estat.fi.c %>%
- group_by(geo) %>%
- mutate(GDPP = 100*values/values[9]) %>%
- filter(time==2013) %>%
- select(region = geo, GDPP = GDPP)
- estat.fi.sel.c$success <- cut(estat.fi.sel.c$GDPP,
- breaks = c(-Inf,100,Inf),
- labels = c("failure","success"))
- lp.fi.gdpp <- left_join(lp.fi,estat.fi.sel.c,by = c("NUTS_ID" = "region"))
- ggplot(lp.fi.gdpp, aes(x=long,y=lat,group=group,fill=success),color="white") + geom_polygon() +
- ggtitle("Recuperation of GDP in Finland\nin 2014 to the level in 2008")
- ggplot(lp.fi.gdpp, aes(x=long,y=lat,group=group,fill=GDPP),color="white") + geom_polygon() +
- ggtitle("Recuperation of GDP in Finland\nin 2014 [% of 2008 GDP]")
- # Lets repeat for Hungary
- lp.hu <- lp %>% filter(grepl('HU',NUTS_ID) & STAT_LEVL_ == 3)
- lp.hu$NUTS_ID <- droplevels(lp.hu$NUTS_ID)
- regions.hu <- levels(lp.hu$NUTS_ID)
- # NUTS 3 level GDP time series in HU
- estat.hu <- get_eurostat('nama_10r_3gdp',
- filters = list(unit = 'EUR_HAB',
- geo = regions.hu),
- time_format = 'num',
- type = 'label')
- estat.hu.sel <- estat.hu %>% filter(!is.na(values) & time>=2008) %>%
- select(region = geo, year = time, GDP = values) %>%
- group_by(region) %>%
- mutate(GDPP = 100*GDP/GDP[1])
- ggplot(estat.hu.sel,aes(x=year,y=GDP,color=region)) + geom_line() +
- scale_colour_discrete(guide = 'none') +
- expand_limits(x=2015) +
- geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
- ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
- labs(x="Year",y="GDP\n[EUR]")
- ggplot(estat.hu.sel,aes(x=year,y=GDPP,color=region)) + geom_line() +
- scale_colour_discrete(guide = 'none') +
- expand_limits(x=2015) +
- geom_dl(aes(label = region), method = "last.qp", cex = 0.4) +
- ggtitle("GDP of regions in Finland\nafter the 2008 crash") +
- labs(x="Year",y="GDP\n[% of 2008 GDP]") +
- geom_hline(yintercept=100)
- # see on map the winners and loosers
- estat.hu.c <- get_eurostat('nama_10r_3gdp',
- filters = list(unit = 'EUR_HAB',
- geo = regions.hu),
- time_format = 'num')
- estat.hu.sel.c <- estat.hu.c %>%
- group_by(geo) %>%
- mutate(GDPP = 100*values/values[9]) %>%
- filter(time==2014) %>%
- select(region = geo, GDPP = GDPP)
- estat.hu.sel.c$success <- cut(estat.hu.sel.c$GDPP,
- breaks = c(-Inf,100,Inf),
- labels = c("failure","success"))
- lp.hu.gdpp <- left_join(lp.hu,estat.hu.sel.c,by = c("NUTS_ID" = "region"))
- ggplot(lp.hu.gdpp, aes(x=long,y=lat,group=group,fill=success),color="white") + geom_polygon() +
- ggtitle("Recuperation of GDP in Hungary\nin 2014 to the level in 2008")
- ggplot(lp.hu.gdpp, aes(x=long,y=lat,group=group,fill=GDPP),color="white") + geom_polygon() +
- ggtitle("Recuperation of GDP in Hungary\nin 2014 [% of 2008 GDP]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement