我目前正在使用R来创建带有制图包的地图。 我的原始数量有问题。 我已经搜索了两天没有,但我找不到任何东西。
这是我的全部剧本:
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)
错误发生在脚本的末尾,就在使用&#34; propsymbolsChoroLayer&#34;之后。
坦克很多,