Gosti draw Var.R AnimXbwealth

From InterSciWiki
Jump to: navigation, search

Giorgio Gosti drawVar.R Gosti draw Var.R FxCmtyWages

Giorgio Gosti drawVar.R modified, SFI Working group in Causal Analysis
AnimXbwealth Giorgio Gosti drawVar.R, SFI Working group in Causal Analysis
#------------------------------------------------
#This file works only if in the same folder of 'comb.RData'
#----------------------------------------------------------
setwd('/Users/drwhite/Documents/3sls/sccs/')
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)))      
load('sccs.Rdata')
AnimXbwealth=sccs$v206*(sccs$v208==1)*1
HiAnim<-(AnimXbwealth>=5)*1     
dep_var<-HiAnim   ####sccs$HiGod4  #sccs$v238  if you start with
for (i in 1:186) {
if (dep_var[i]==0) dep_var[i]<-' '}
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=dep_var   #sccs$HiGod4
for(i in s2$name[-length(s2$name)]){           #draw values of variable in list
       if(varcateg[i] == 0) text(s2$long[i], s2$lat[i],  varcateg[i], pos=1, col ="black")
       if(varcateg[i] == 1) text(s2$long[i], s2$lat[i],  varcateg[i], pos=1, col ="red") #black")
       if(varcateg[i] == 2) text(s2$long[i], s2$lat[i],  varcateg[i], pos=1, col ="dark gray")
       if(varcateg[i] == 3) text(s2$long[i], s2$lat[i],  varcateg[i], pos=1, col ="dark orange")
       if(varcateg[i] == 4) text(s2$long[i], s2$lat[i],  varcateg[i], pos=1, 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()
Personal tools