Ressources numériques en sciences humaines et sociales OpenEdition Nos plateformes OpenEdition Books OpenEdition Journals Hypothèses Calenda Bibliothèques OpenEdition Freemium Suivez-nous

[R] Faire une carte par points avec R

Voici ci-dessous le code R pour réaliser une carte en points à partir d’un fond de carte et d’une donnée quantitative absolue.

Screenshot from 2014-03-04 09:58:58

# VARIABLES
mygeom<-“nuts3_2006.shp”
mydata<-“data_nuts3.csv”
myvar<-“pop_t_2008”
nb<-100 # Un point vaut nb units
library(maptools)
setwd(“/home/nlambert/Documents/R/carto”)
list.files()fdc <- readShapeSpatial(mygeom)
donnees<-read.csv(mydata ,header=TRUE,sep=”\t”,dec=”,”,encoding=”latin1″,)
colnames(fdc@data)[1]<-“id”
names(donnees)[1]<-“id”
fdc@data <- data.frame(fdc@data, donnees[match(fdc@data[,”id”], donnees[,”id”]),])
fdc@data<-data.frame(fdc@data$id,fdc@data[,myvar])
colnames(fdc@data)<-c(“id”,”var”)
fdc@data$var[is.na(fdc@data$var)] <- 0
fdc@data$nbdots <-as.integer(fdc@data$var/nb)
dots<-dotsInPolys(fdc, as.integer(fdc@data$nbdots),f = “random”)
plot(fdc,col=”#CCCCCC”,border=”white”)
plot(dots, pch=20, coll=”black”,add=TRUE,cex=0.01)

OpenEdition vous propose de citer ce billet de la manière suivante :
Nicolas Lambert (4 mars 2014). [R] Faire une carte par points avec R. Carnet (neo)cartographique. Consulté le 18 juin 2025 à l’adresse https://doi.org/10.58079/rreb


Nicolas Lambert

Ingénieur de recherche CNRS en sciences de l'information géographique. Membre de l'UMS RIATE et du réseau MIGREUROP / CNRS research engineer in geographical information sciences. Member of UMS RIATE and the MIGREUROP network.

Vous aimerez aussi...

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

This site uses Akismet to reduce spam. Learn how your comment data is processed.