From 97db5634c2117c4e4c7071fd82ca4ca8aa7a3d41 Mon Sep 17 00:00:00 2001 From: Kevin Cazelles Date: Mon, 8 May 2017 10:29:39 -0400 Subject: [PATCH] update readme --- R/mapElections.R | 21 +++++++++++---------- README.md | 30 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/R/mapElections.R b/R/mapElections.R index 5c6b012..1a92df9 100644 --- a/R/mapElections.R +++ b/R/mapElections.R @@ -5,8 +5,9 @@ library(htmlwidgets) library(htmltools) library(leaflet) library(rgdal) +library(highcharter) -## +## wrld_adm <- readRDS("data/worldsimpleready.Rds") ## Remove France @@ -30,7 +31,7 @@ for (i in 1:nbc) { id <- which(rk2 == j) vot <- wrld_adm@data[i, id + 4] pct <- round(100 * vot/wrld_adm@data$voteTot[i], 2) - ls_labels[i] %<>% paste0("
", j, ". ", names(wrld_adm@data)[id + + ls_labels[i] %<>% paste0("
", j, ". ", names(wrld_adm@data)[id + 4], " : ", vot, " soit ", pct, "%") } } @@ -38,7 +39,7 @@ for (i in 1:nbc) { ls_labels %<>% lapply(htmltools::HTML) ## COLORS (only 4 winners...) -vec_col <- c("white", "#232f70", "#232f70", "#01b2fb", "#97c121", "#c9462c", "#c9462c", +vec_col <- c("white", "#232f70", "#232f70", "#01b2fb", "#97c121", "#c9462c", "#c9462c", "#232f70", "#c9462c", "#c9462c", "#232f70", "#c9a00e") ls_col <- vec_col[vec_pos + 1] %>% as.list @@ -47,15 +48,15 @@ ls_col <- vec_col[vec_pos + 1] %>% as.list ## Creating the Map using leaflet; cat("\n---- CREATING THE MAP ----\n") -map_elec <- leaflet(wrld_adm) %>% setView(lng = 5, lat = 10, zoom = 3) %>% addTiles() %>% - addPolygons(weight = 2, opacity = 1, color = ls_col, dashArray = "3", fillOpacity = 0.7, - highlight = highlightOptions(weight = 3, color = "#666", dashArray = "", - fillOpacity = 0.7, bringToFront = TRUE), label = ls_labels, labelOptions = labelOptions(style = list(`font-weight` = "normal", - padding = "3px 8px"), textsize = "15px", direction = "auto")) %>% addEasyButton(easyButton(icon = "fa-github-square fa-2x", - title = "View source code", onClick = JS("function(btn){window.location.href = 'https://github.com/letiR/Elections_fr-042017';}"), +map_elec <- leaflet(wrld_adm) %>% setView(lng = 5, lat = 10, zoom = 3) %>% addTiles() %>% + addPolygons(weight = 2, opacity = 1, color = ls_col, dashArray = "3", fillOpacity = 0.7, + highlight = highlightOptions(weight = 3, color = "#666", dashArray = "", + fillOpacity = 0.7, bringToFront = TRUE), label = ls_labels, labelOptions = labelOptions(style = list(`font-weight` = "normal", + padding = "3px 8px"), textsize = "15px", direction = "auto")) %>% addEasyButton(easyButton(icon = "fa-github-square fa-2x", + title = "View source code", onClick = JS("function(btn){window.location.href = 'https://github.com/letiR/Elections_fr-042017';}"), position = "topright")) %>% addProviderTiles(providers$Esri.WorldImagery) -## +## cat("\n---- SAVING THE MAP ----\n") saveWidget(widget = map_elec, file = "index.html") diff --git a/README.md b/README.md index 1ef7e97..62ada6b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ ## Elections_fr-042017 + Cartographie du vote des français de l'étranger - 1er Tour - 2017 Carte réalisée avec Leaflet (appelé via R, voir les packages utilisés ci-dessous et la [documentation](https://rstudio.github.io/leaflet/)). @@ -12,17 +13,16 @@ https://www.data.gouv.fr/fr/datasets/resultats-du-vote-des-francais-residant-a-l - Données pour les frontières administratives sont disponibles en ligne, nous avons utilisé la version 2.8 de GADM [GADM](ttp://www.gadm.org/version2). Nous avons simplement simplifié ces données pour les rendre plus légères (function `gSimplify()` du package R `rgeos`, voir le fichier `simpleWorld.R`). -## Packages R requis +## Liste des Packages R requis + +1. magrittr +1. htmlwidgets +1. htmltools +1. leaflet +1. countrycode +1. rgdal +1. stringdist -```r -library(magrittr) -library(htmlwidgets) -library(htmltools) -library(leaflet) -library(countrycode) -library(rgdal) -library(stringdist) -``` ## TODO @@ -30,9 +30,9 @@ library(stringdist) - [X] merger les résultats de Jérusalem avec Israël; - [X] couleur pour le gagnant; - [X] détails des résultats; -- [ ] faire la France?; -- [ ] Inverser les couleurs entre le candidat macron et fillon (http://www.lemonde.fr/les-decodeurs/article/2017/04/26/presidentielle-les-francais-de-l-etranger-ont-vote-macron-a-40-au-premier-tour_5117947_4355770.html) -- [ ] Ajouter une légende -- [ ] Ajouter le titre +- [X] faire la France => voir https://github.com/letiR/fr-departement-election +- [ ] Inverser les couleurs entre le candidat macron et fillon (http://www.lemonde.fr/les-decodeurs/article/2017/04/26/presidentielle-les-francais-de-l-etranger-ont-vote-macron-a-40-au-premier-tour_5117947_4355770.html) NB +on change sur la prochaine carte +- [X] Ajouter une légende +- [X] Ajouter le titre - [ ] Ajouter les couches par candidats -- [ ] on pourrait faire un score gauche/droite et un score système/anti-système (Je pense que ca forcerait l'interprétation (SV).)