class: center, middle, inverse, title-slide # Dealing with the change of administrative divisions over time with
### Kim Antunez
antuki13 ### useR! 2019 - Toulouse, France 11 July 2019 --- ## Administrative divisions... .left-column[ <img src="img/millefeuille2.png" height="60px"></img> <img src="img/millefeuille1.png" height="400px"> ] .right-column[ <center>The French territorial « mille-feuille »</center></br> <center><img src="img/carte_millefeuille_v2.png"></center> ] --- ## ... change over time <center><img src="img/map_fusions.png" height="500px"></center> --- .pull-left[ ### See modifications over the years ] .pull-right[ <center><img src="img/trajectoires.png" height="100px"></center> ]
All functions and parameters are translated from French for this presentation ```r municipality_evolution_graph(code = "76108", year = 2014) # uses {visNetwork} ``` <center><img src="img/trajectoire_commune.png" height="100px"></center> ```r evol <- municipalities_evolutions(begin_date="01-01-2011", end_date="01-01-2014") ``` ```r grep("(76095)|(76108)", evol$mergers, value = TRUE) ``` ``` ## 2012-01-01: Bois-Guillaume-Bihorel (76108) is a merger of Bihorel (76095), Bois-Guillaume (76108). ``` ```r grep("(76095)|(76108)", evol$divisions, value = TRUE) ``` ``` ## 2014-01-01: Bois-Guillaume (76108) divided into Bois-Guillaume (76108), Bihorel ## (76095). ``` --- .pull-left[ ### Guess the year of a database ] .pull-right[ <center><img src="img/tableau_year.png" height="100px"></center> ] ```r head(db, 2) ``` ``` ## code men women ## 1 01001 385.0000 380.000 ## 2 01002 142.6132 113.107 ``` ```r OGC_guess(db$code) # guesses the year of the Official Geographic Code (OGC) ``` ``` ## [1] "2016" ``` ```r codes <- c("99086", db$code[-1]) # creates a vector of ID of municipalities merge_OGC(codes = codes, OGC = 2016)$not_in_db # ID not in the db ``` ``` ## 01001 ``` ```r merge_OGC(codes = codes, OGC = 2016)$not_in_OGC # ID not in the OGC ``` ``` ## 99086 ``` --- .pull-left[ ### Change the year of a database * **qualitative variable** [character]</br>
See `change_OGC_typology` + *divisions *
easy: copy the lines + *mergers *
several hypotheses: assign the class that contains the most population, define an absorbent or absorbed class... ] .pull-right[ <center><img src="img/tableau_year2.png" height="100px"></center> * **quantitative variable** [numeric]</br>
See `change_OGC_numeric` + *mergers *
easy: sum the lines + *divisions *
divide lines proportionally to population ] ```r nrow(db) ``` ``` ## [1] 35887 ``` ```r db_2019 <- db %>% # changes the year of a numeric variable (from 2016 to 2019) change_OGC_numeric(2016:2019) ``` ```r str(db_2019) ``` ``` ## 'data.frame': 34972 obs. of 3 variables: ## $ code : chr "01001" "01002" "01004" "01005" ... ## $ men : num 385 142.6 6778.5 819 54.5 ... ## $ women: num 380 113.1 7246.5 783.9 49.5 ... ``` --- .pull-left[ ### Aggregate a database ] .pull-right[ <center><img src="img/agreger.png" height="100px"></center> ] ```r db_dep <- db_2019 %>% # aggregates the database (municipalities -> départements) aggregate_OGC(OGC = 2019, administrative_division = "DEP") ``` ```r str(db_dep) ``` ``` ## 'data.frame': 100 obs. of 4 variables: ## $ DEP : chr "01" "02" "03" "04" ... ## $ LIBGEO: chr "Ain" "Aisne" "Allier" "Alpes-de-Haute-Provence" ... ## $ men : num 309198 262693 163759 78600 68309 ... ## $ women : num 316839 276817 179006 83124 71588 ... ``` ```r DEP_sf <- left_join(DEP_sf,db_dep,by=c("DEP"="DEP")) %>% mutate(prop=100*men/(men+women)) plot(DEP_sf %>% select(prop)) ``` <center><img src="img/draw_prop.png" height="200px"></center> --- ## Future improvements? * **Create new functions** + add your own geographical levels + add your own distribution keys * **Expand to other countries** + in Europe : Nomenclature of Territorial Units for Statistics (NUTS) + identify common functionnalities VS local (French!) specificities * **Reach non R-users** + Shiny Apps + API --- class: center, middle <center><img src="img/avatar.png" height="300px"></center> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <a href="http://twitter.com/antuki13" class="social"><i class="fa fa-twitter fa-2x" title="Mon twitter"></i>@antuki13</a> <a href="http://github.com/antuki" class="social"><i class="fa fa-github fa-2x" title="Mon github"></i>antuki</a> <a href="http://antuki.github.io" class="social"><i class="fa fa-bold fa-2x" title="Mon blog"></i>antuki.github.io</a> **Packages on github: [antuki/COGugaison](https://github.com/antuki/COGugaison) and [antuki/CARTElette](https://github.com/antuki/CARTElette).** Slides created with R package [**xaringan**](https://github.com/yihui/xaringan) with the [R-Ladies theme](https://alison.rbind.io/post/r-ladies-slides/). Also with [remark.js](https://remarkjs.com), [knitr](http://yihui.name/knitr), and [R Markdown](https://rmarkdown.rstudio.com).