Giorgio Gosti drawVar.R
From InterSciWiki
Revision as of 08:45, 9 November 2011 by Douglas R. White (Talk | contribs)
- Gosti draw Var.R AnimXbwealth - Giorgio Gosti drawPath.R - SCCS R package
- http://cran.r-project.org/web/packages/maps/maps.pdf
setwd('/Users/drwhite/Documents/3sls/sccs/')
load('sccsfac.Rdata')
sccs<-data.frame(sapply(sccsfac,function(x) as.numeric(x)))
AnimXbwealth=sccs$v206*(sccs$v208==1)*1
#------------------------------------------------ #This file works only if in the same folder of 'comb.RData' #------------------------------------------------ install.library(maps)
#optional
map('world', fill = FALSE, col = "blue")
#grid()
#loads data
load('comb.RData')
sccs<-data.frame(sapply(comb,function(x) as.numeric(x)))
dep_var<-sccs$HiGod4 #sccs$v238 if you start with
load('sccs.Rdata')
s <- data.frame(long = sccs$longitud, lat = sccs$latitude, name = sccs$sccsnum) s2 <- s[with(s, order(name)), ]
#draws map library(maps)
map('world', fill = FALSE, col = "white") #WHITE
#grid()
#optional
map('world', fill = FALSE, col = "blue")
# points(s2$long,s2$lat, pch=20, col = "green")
#draws path
for(i in s2$name[-length(s2$name)])
if(s2$long[i]-s2$long[i+1]<180 && s2$long[i]-s2$long[i+1]>-180)
segments(s2$long[i],s2$lat[i],s2$long[i+1],s2$lat[i+1])
for(i in s2$name[-length(s2$name)]){
if(s2$long[i+1]-s2$long[i]>180){
sl <- (s2$lat[i+1]-s2$lat[i])/(360-s2$long[i+1]+s2$long[i])
segments(s2$long[i],s2$lat[i],-180,s2$lat[i] - sl * (-180-s2$long[i]), col = "black")
segments(s2$long[i+1],s2$lat[i+1],180,s2$lat[i+1] - sl * (180-s2$long[i+1]), col = "black")
}
}
#line segments were drawn
for(i in s2$name[-length(s2$name)]){
if(s2$long[i+1]-s2$long[i] < -180){
sl <- (s2$lat[i+1]-s2$lat[i])/(360 + s2$long[i+1] - s2$long[i])
segments(s2$long[i],s2$lat[i],180,s2$lat[i] + sl * (180-s2$long[i]), col = "black")
segments(s2$long[i+1],s2$lat[i+1],-180,s2$lat[i+1] + sl * (-180-s2$long[i+1]), col = "black")
# segments(s2$long[i],s2$lat[i],s2$long[i+1],s2$lat[i+1], col = "red")
}
}
###draws society numbers
##for(i in s2$name[-length(s2$name)]){
## if(i%%6 != 1) text(s2$long[i], s2$lat[i], s2$name[i], pos=4, col ="lightgrey")
##}
varcateg=sccs$HiGod4
for(i in s2$name[-length(s2$name)]){ #draw values of variable in list
if(varcateg[i] <= 1) text(s2$long[i], s2$lat[i], varcateg[i], pos=3, col ="black")
if(varcateg[i] == 2) text(s2$long[i], s2$lat[i], varcateg[i], pos=3, col ="dark gray")
if(varcateg[i] == 3) text(s2$long[i], s2$lat[i], varcateg[i], pos=3, col ="dark orange")
if(varcateg[i] == 4) text(s2$long[i], s2$lat[i], varcateg[i], pos=3, col ="red")
#text(s2$long[i], s2$lat[i], varcateg[i], pos=4, col ="black")
}
text(s2$long[186], s2$lat[186], varcateg[186], pos=3, col ="black")
#now has drawn lines and Colored Numbers for HiGod4
dev.copy2pdf() # dev.copy(png,'myMap.png') # dev.off()

