0

I am currently using R to create a map with the cartography package. I have a problem with the numbers of raws. I have search an anwser for two days no but I can't find anything.

This is all my script :

rm(list=ls())
library(foreign)
library (maptools)
library(cartography)
library(RColorBrewer)
library(maptools)
library(classInt)

fdc <- readShapeSpatial("DEPARTEMENT")

library(rgdal)
fdc <- readOGR(dsn="19-correze", layer="19-")
proj4string(fdc)
fdc <- spTransform(fdc, CRS ("+init=epsg:4326") )
head(coordinates(fdc))
plot(fdc)

vil <- read.csv("villes_france.csv", header=FALSE, sep =",")
vil2 <- subset(vil, select=c(V2,V3,V16,V20,V21))
names(vil2) <- c("CODE_DEPT", "NOM_VILLE", "POP", "LONG", "LAT")
vil3 <- vil2[vil2$CODE_DEPT==19,]
vil3[,c("POP", "LONG", "LAT")] <- sapply(vil3[,c("POP", "LONG", 
"LAT")], 
as.numeric)
head(vil3)
vil3 <- vil3[order(-vil3$POP),]
points(vil3$LONG[1:100],vil3$LAT[1:100],pch=20,col="grey", 
inches=0.02,cex=1)

head (vil3)
library(foreign)
mat <- read.csv( "FRAD019_indexation_matricule_extrait.csv", 
header=TRUE, 
sep =";")
mat <- mat[!(mat$Degre.d.instruction.generale=="non renseigne"),]
mat$educ <- as.numeric(mat$Degre.d.instruction.generale)
educ <- aggregate(educ ~ commune.de.naissance + classe, data=mat, 
FUN=mean, na.rm=TRUE, na.action="na.pass")


library(foreign)
mat <- read.csv("FRAD019_indexation_matricule_extrait.csv", header = 
TRUE, sep = ";")
mat <- mat[!(mat$Individu=="non renseigné"),]
mat$educ2 <- as.numeric(mat$Individu)
educ2 <- aggregate(educ2 ~ commune.de.naissance + classe, data=mat, 
FUN=sum, na.rm=TRUE, na.action="na.pass")

educ <- merge (educ,educ2,by=c("commune.de.naissance"), all.y=TRUE)
names(educ) <- c("NOM_VILLE","CLASSE","EDUC","CLASSE", "MOY")

educ$NOM_VILLE <- tolower(educ$NOM_VILLE)
vil3$NOM_VILLE <- gsub("-19", "", vil3$NOM_VILLE)
vil4 <- merge(vil3,educ,by=c("NOM_VILLE"),all.y=TRUE, row.names=NULL)
vil4[,c("CODE_DEPT", "EDUC", "MOY")] <- sapply(vil4[,c("CODE_DEPT", 
"EDUC", "MOY")], as.numeric)

vil4 <- subset(vil4, select=c("CODE_DEPT", "CLASSE", "EDUC", "MOY"))
fdc@data <- merge(fdc@data,vil4, by="CODE_DEPT", all=TRUE, 
row.names=NULL,check.rows = FALSE,
check.names = FALSE)

propSymbolsChoroLayer(spdf = fdc, 
df = df,
var = "MOY",
inches = 0.07,
fixmax = 4,
symbols = "circle",
var2 = "EDUC",
col = carto.pal(pal1 = "turquoise.pal", n1 = 8),
breaks = c(0,1,2,3),
lwd = 1.5, 
legend.var.pos = "topleft", 
legend.var.values.rnd = -3, 
legend.var.title.txt = "Total Population", 
legend.var.style = "e", 
legend.var2.pos = "bottomright", 
legend.var2.title.txt = "Compound Annual\nGrowth 
Rate", add= TRUE)

The error is at the end of the script, just after using "propsymbolsChoroLayer".

Tanks a lot,

Maelle AM
  • 1
  • 2
  • 1
    Please you specify which specific line of code is producing the error. – Djork May 04 '17 at 23:52
  • @R.S. is it great now ? – Maelle AM May 05 '17 at 01:21
  • You will have to provide a minimum reproducible example on which we can run your code. Remember that your .csv files are not accessible to us. You have quite a bit of variables but I think the only relevant ones are the inputs to `spdf` and `df`, so you can paste the output of `dput(fdc)` and `dput(df)`. I don't see a variable `df` defined in your code, and you use this as input to `propSymbolsChoroLayer` so you will need to add that. – Djork May 18 '17 at 02:33

0 Answers0