Giorgio Gosti drawVar.R

From InterSciWiki
Jump to: navigation, search

Giorgio Gosti

Giorgio Gosti drawVar.R modified, SFI Working group in Causal Analysis
Giorgio Gosti drawPath.R by Giorgio Gosti, SFI Working group in Causal Analysis
DRW version-Plow
setDS("SCCS") # creates objects: "cov" "dx"  "dxf" "key" "wdd" "wee" "wll"
one can use the metadata data frame called “key” to get the descriptions.
For example, if one wants the description for “v874”, do the following:
> key["v874","description"] #-Anthon
setwd('/Users/drwhite/Documents/3sls/sccs/')		
#load('sccsfac.Rdata') 
#sccs<-data.frame(sapply(sccsfac,function(x) as.numeric(x)))	
#load('sccs_fac.Rdata') 
#sccs<-data.frame(sapply(sccs_fac,function(x) as.numeric(x)))
load(url("http://dl.dropbox.com/u/9256203/sccsA.Rdata"),.GlobalEnv)  #new
sccs<-data.frame(sapply(sccsA,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)
library(maps)
library(psych) #for corr.test
#optional
map('world', fill = FALSE, col = "light blue")
#grid()
#loads data
load('comb.RData')
sccs<-data.frame(sapply(comb,function(x) as.numeric(x)))
 aa<-aggregate(smi[,sapply(smi,function(x) is.numeric(x))],list(smi$.id),mean) #Anthon Eff  HAVE TO HAVE RUN DEf first, perhaps separately
dep_var<-sccs$HiGod4  #sccs$v238  WORKS    
sccsA$plow=(sccsA$v243>1)*1
dep_var<-(sccs$v243>1)*1  #sccsA$plow=(sccsA$v243>1)*1 #sccs$v238  NOT WORKING see Giorgio Gosti drawVar2.R
dep_var<-sccs$v676 #3=feminine creation figures? WORKS
dep_var<-2 - sccs$v626 #2=Inferiority WORKS
dep_var<-4 - sccs$v621 #3=Men Should and Do Dominate their Wives WORKS
dep_var<-5 - sccs$v628 #4=Women do not control their Property WORKS
dep_var<-sccs$v664 #2=Present, Ideology of Male Toughness
dep_var= replace(dep_var,is.na(dep_var),-1) 
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 = "light 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], col = "red")  #autocorrelation path
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 = "red")  #col = "black")
               segments(s2$long[i+1],s2$lat[i+1],180,s2$lat[i+1] - sl * (180-s2$long[i+1]), col = "red")  #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 = "red") #light gray")  #col = "black")
               segments(s2$long[i+1],s2$lat[i+1],-180,s2$lat[i+1] + sl * (-180-s2$long[i+1]), col = "red") #light gray") #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            #was sccs$HiGod4
for(i in s2$name[-length(s2$name)]){           #draw values of variable in list UP TO 185)
       if(varcateg[i] ==  1) text(s2$long[i], s2$lat[i]-8,  varcateg[i], pos=3, col ="gray")   #"black")
       if(varcateg[i] == -1) text(s2$long[i], s2$lat[i]-8,  varcateg[i], pos=3, col ="pink")
       if(varcateg[i] ==  2) text(s2$long[i], s2$lat[i]-8,  varcateg[i], pos=3, col ="dark gray")
       if(varcateg[i] ==  1) text(s2$long[i], s2$lat[i]-8,  varcateg[i], pos=3, col ="black") #dark orange")
       if(varcateg[i] ==  2) text(s2$long[i], s2$lat[i]-8,  varcateg[i], pos=3, col ="black") #"red")
      #text(s2$long[i], s2$lat[i],  varcateg[i], pos=4, col ="black")
}
i=186
       if(varcateg[i] ==  1) text(s2$long[186], s2$lat[186]-8,  varcateg[186], pos=3, col ="gray") #LAST OF 186 values
       if(varcateg[i] == -1) text(s2$long[186], s2$lat[186]-8,  varcateg[186], pos=3, col ="pink") #LAST OF 186 values
       if(varcateg[i] ==  2) text(s2$long[186], s2$lat[186]-8,  varcateg[186], pos=3, col ="black") #LAST OF 186 values
       if(varcateg[i] ==  1) text(s2$long[186], s2$lat[186]-8,  varcateg[186], pos=3, col ="dark gray") #LAST OF 186 values
       if(varcateg[i] ==  2) text(s2$long[186], s2$lat[186]-8,  varcateg[186], pos=3, col ="black") #"red") #LAST OF 186 values
#now has drawn lines and Colored Numbers for HiGod4
dev.copy2pdf()
# dev.copy(png,'myMap.png')
# dev.off()