This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgdal) | |
library(maptools) | |
library(classInt) | |
setwd("F:/METHODES/1205_CAMPAGNE_PRES") | |
######################### | |
## READING SOURCE DATA ## | |
######################### | |
# on intègre les contours des communes GEOFLA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ATTENTION !!: l'utilisation de ce code nécessite d'avoir | |
# lancé le code précédent (https://gist.github.com/2857180) , | |
# en gros d'avoir créé l'objet spatial comm2 avec les résultats du vote. | |
library(rgdal) | |
library(spatstat) | |
library(maptools) | |
## COERCING DATA for SPATSTAT ## | |
# on lit le trait de côte téléchargé depuis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgdal) | |
# DATA | |
# http://professionnels.ign.fr/ficheProduitCMS.do?idDoc=6185461 | |
cities <- readOGR("C:/DATAS/GEOFLA/COMMUNES/COMMUNE.SHP", "COMMUNE") | |
# http://www.data-publica.com/opendata/13495--resultats-du-deuxieme-tour-de-l-election-presidentielle-2012 | |
votes <- read.csv2("IN/votesResults2012.csv",sep=",", quote="\"") | |
# VOTES TO SPATIAL DATA " | |
votes$pc.sar <- votes$results.sarkozy / votes$results.exprimes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gdata) | |
library(reshape) | |
library(classInt) | |
############### | |
# INTEGRATING # | |
############### | |
f <- read.xls("IN/Leg 2012 Candidatures T1 31 05 2012.xls", sheet=1) | |
nuances <- read.xls("IN/Leg 2012 Candidatures T1 31 05 2012.xls", sheet=2, skip=2, header=FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gdata) | |
library(stringr) | |
#Fichier source : http://www.data-publica.com/data/13622--resultat-par-circonscription-du-2nd-tour-des-elections-legislatives-17-juin-2012 | |
res <- read.xls("IN/Leg 2012 Résultats CirLG FE T2.xls") # résultats législatifs | |
########################### | |
# RECUPERATION DU GAGNANT # | |
########################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##[datagistips]=group | |
##polygons=vector | |
##distance=number 10 | |
##output=output vector | |
library("spdep") | |
nb = poly2nb(polygons, snap=distance) | |
polygons[["nNeigh"]] = card(nb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgdal) | |
library(spdep) | |
pol <- readOGR(".", "buildings") # read the data using rgdal | |
nb <- poly2nb(pol, snap=50) # create a graph. Two buildings are connected if they are 50 meters apart from one another. | |
pol$nNeigh <- card(nb) # card(nb) gives the neighbor counts | |
pol$neighGroup <- n.comp.nb(nb)$comp.id # n.comp.nb contains the informations about the disconnected compontents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgdal) | |
library(wordcloud) | |
library(reshape) | |
library(maptools) | |
library(classInt) | |
library(FactoMineR) | |
library(FNN) | |
### LOAD DATA ### | |
f <- readOGR(".", "COMMUNE") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgdal) | |
library(spatstat) | |
library(maptools) | |
library(rgeos) | |
setwd("D:/METHODES/1211_ELONGATEDCOUNTRIES/") | |
countries <- readOGR("D:/DATAS/NATURAL EARTH/ne_110m_admin_0_countries_lakes/ne_110m_admin_0_countries_lakes.shp", "ne_110m_admin_0_countries_lakes") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgdal) | |
countries <- readOGR("D:/DATAS/NATURAL EARTH/ne_110m_admin_0_countries_lakes/ne_110m_admin_0_countries_lakes.shp", "ne_110m_admin_0_countries_lakes") | |
first <- substr(as.character(countries$name),0,1) # on détermine la première lettre du nom du pays | |
first[grep("Sahara", countries$name)] <- "S" | |
first[grep("Guinea", countries$name)] <- "G" | |
first[grep("Korea", countries$name)] <- "K" | |
first[grep("Congo", countries$name)] <- "C" | |
first[grep("Antarctic", countries$name)] <- "A" |
OlderNewer