Nine nations

ninenationsall.jpg

Let us produce the clustering (partition) nine described in matching9nations.doc and corrections in corrections.doc and corrections2.doc. We start with a partition in which we assign complete states to 9nations. The final partition is obtained by corrections of this partition according to the assignments specified in the file 9nationsClu.csv - it is stored in 9nations.zip.

> setwd("D:/Data/counties/9nations")
> library(maptools)
> gpclibPermit()
> USsta <- readShapeSpatial("USA/USA_adm1.shp")  # state borders
> UScou <- readShapeSpatial("USA/USA_adm2.shp")  # county borders
> load('pq.Rdata')
> state <- read.csv("../pajek/states3110.clu",header=FALSE,skip=1)$V1
> col <- c("red","yellow","green","blue","pink","brown","orange","purple","grey","white")
> nine <- rep(NA,3110)
> nine[state %in% c(25,33,50,44,23)] <- 1                              # New England
> nine[state %in% c(36,34,24,42,39,26)] <- 2                           # Foundry
> nine[state %in% c(54,51,21,37,45,47,13,1,28,22,5,12)] <- 3           # Dixie
> nine[state %in% c(48,35,6)] <- 5                                     # Mexamerica
> nine[state %in% c(41,53)] <- 6                                       # Ecotopia
> nine[state %in% c(4,56,30,49,16,32,8)] <- 7                          # The Empty Quarter
> nine[state %in% c(17,19,20,27,31,38,46,40,55,29)] <- 8               # The Breadbasket>
> ids <- read.csv("../usc3110lab.csv",header=FALSE,stringsAsFactors=FALSE)
> id <- ids$V2 <- standard(ids$V2)
> S <- read.csv(file="states.csv",stringsAsFactors=FALSE,sep=";")
> states <- levels(UScou$NAME_1); ps <- match(states,S$name)
> names <- paste(UScou$NAME_2,", ",S$code[ps[as.integer(UScou$NAME_1)]],sep="")
> Name <- rep(NA,3110)
> for(v in 1:3110) {i <- q[[p[[v]]]]; if(!is.na(i)) Name[[v]] <- names[[i]]}
> change <- read.csv(file="9nationsClu.csv",stringsAsFactors=FALSE,sep=";",header=TRUE)
> pos <- match(change$County,Name)
> err <- which(is.na(pos))
> cat(change$County[err],'\n')
 
> ok <- which(!is.na(pos))
> posok <- pos[ok]
> nine[posok] <- change$Cluster[ok]
> clu <- rep(NA,length(UScou$NAME_1))
> for(v in 1:3110) {i <- q[[p[[v]]]]; if(!is.na(i)) clu[[i]] <- nine[[v]]}
> UScou$clu <- clu
> UScou$clu[which(is.na(UScou$clu))] <- 10 
>

To check the obtained partition we draw it on the map.

> pdf("USc9nations.pdf",width=11.7,height=8.3,paper="a4r")
> plot(UScou,xlim=c(-124,-67),ylim=c(23,48),col=col[UScou$clu],bg="skyblue",border="black",lwd=0.05)
> plot(USsta,xlim=c(-124,-67),ylim=c(23,48),lwd=0.2,border="violet",add=TRUE)
> text(coordinates(UScou),labels=as.character(UScou$NAME_2),cex=0.1)
> title("Central US"); dev.off()
> save(nine,file='nineClu.Rdata')
> out <- file("9nations.clu","w"); cat("*vertices 3110",nine,sep="\n",file=out); close(out)

The detailed map (~ 50 Mb).

notes/clu/counties/nine.txt · Last modified: 2017/04/12 19:05 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki