#!/usr/bin/env python # coding: utf-8 # # *Statistics coded*: Young people - social inclusion # # Prepared by [**J.Grazzini**](mailto:jacopo.grazzini@ec.europa.eu) (*Eurostat*). # # This notebook illustrates the principles of storytelling through literate programming by reproducing some of the figures of the _Statistics Explained_article on [**young people and social inclusion**](https://ec.europa.eu/eurostat/statistics-explained/index.php?title=Young_people_-_social_inclusion). # In[38]: library("eurostat") library("ggplot2") library("tidyr") # In[2]: library(repr) options(repr.plot.width=8, repr.plot.height=3) # In[60]: id = "ilc_li02" # id <-search_eurostat("At-risk-of-poverty rate by poverty threshold, age and sex")$code[1] dat <-get_eurostat(id, time_format = "num", filters = list(age="Y16-29", time="2017", unit="PC")) head(dat) # In[17]: ctries <- c("EU28", "DK", "RO", "ES", "EL", "IT", "SE", "BG", "LU", "PT", "NL", "DE", "FI", "IE", "BE", "FR", "EE", "AT", "UK", "PL", "HR", "CY", "LV", "HU", "SK", "MT", "SI", "CZ", "NO", "CH", "IS", "RS", "MK", "TR") # In[18]: p<-ggplot(data=subset(dat, indic_il == "LI_R_MD60" & sex == "T" & geo %in% ctries), aes(x=reorder(geo, -values), y=values)) + geom_bar(stat="identity", fill="orange") + xlab("Share of young people (aged 16-29 years) at risk of poverty, 2017") + ylab("(%)") print(p) # In[19]: id = "ilc_lvps08" # id <-search_eurostat("Share of young adults aged 18-34 living with their parents by age and sex", fixed = TRUE)$code[1] dat <-get_eurostat(id, time_format = "num", filters = list(time="2017", unit="PC")) head(dat) # In[20]: p<-ggplot(data=subset(dat, geo %in% ctries & sex %in% c("F", "M") & age == "Y16-29"), aes(x=reorder(geo, -values), y=values, fill=sex)) + geom_bar(stat="identity", position=position_dodge()) + xlab("Share of young people (aged 16-29 years) living with their parents, 2017") + ylab("(%)") print(p) # In[23]: p<-ggplot(data=subset(dat, geo %in% ctries & sex == "T" & age %in% c("Y16-29","Y20-24","Y25-29")), aes(x=reorder(geo, -values), y=values, fill=sex, col=age)) + geom_point() + xlab("Share of young people (aged 16-29 years) living with their parents, 2017") + ylab("(%)") print(p) # In[58]: id = "ilc_peps01" # id <-search_eurostat("People at risk of poverty or social exclusion by age and sex")$code[1] dat <-get_eurostat(id, time_format = "num", filters=list(unit="PC", geo="EU28", age="Y16-29")) head(dat) # In[59]: p<-ggplot(data=dat, aes(x=time, y=values, group=sex)) + geom_point() + xlab("Share of young people (aged 16-29 years) at risk of poverty or social exclusion, EU-28, 2007-2017 - by sex") + ylab("(%)") print(p) # In[68]: id = "ilc_li02" # id <-search_eurostat("At-risk-of-poverty rate by poverty threshold, age and sex", fixed = TRUE)$code[1] dat <-get_eurostat(id, time_format = "num", filters = list(unit="PC", geo="EU28", indic_il="LI_R_MD60", sex="T", age=c("Y16-29","Y20-24","Y25-29"))) head(dat) # In[69]: p<-ggplot(data=dat, aes(x=time, y=values, group=age)) + geom_point() + xlab("Share of young people at risk of poverty, EU-28, 2007-2017 - by age") + ylab("(%)") print(p) # In[73]: id = "yth_incl_060" # id <-search_eurostat("Young people's at-risk-of-poverty rate by sex, age and living/not living with parents", fixed = TRUE)$code[1] dat <-get_eurostat(id, time_format = "num", filters = list(time="2016")) head(dat) # In[74]: p<-ggplot(data=subset(dat, geo %in% ctries & age == "Y16-29"), aes(x=reorder(geo, -values), y=values, fill=hhstatus)) + geom_bar(stat="identity", position=position_dodge()) + xlab("Share of young people (aged 16-29 years) at risk of poverty, 2016 - by HH status") + ylab("(%)") print(p) # In[ ]: