Giorgio Gosti drawPath.R

From InterSciWiki
Jump to: navigation, search
Giorgio Gosti drawPath.R by Gosti & White, SFI Working group in Causal Analysis
Giorgio Gosti drawPath.R by Giorgio Gosti, SFI Working group in Causal Analysis
Giorgio Gosti drawPath.R by Giorgio Gosti, SFI Working group in Causal Analysis

SCCS R package - Giorgio Gosti drawVar.R ---

plot(long,lati, cex=.1)
#plot(lon,lat, cex=.1)
# text(lon,lat,ztxt)
#This file works only if in the same folder of 'comb.RData'
#loads data
sccs<-data.frame(sapply(comb,function(x) as.numeric(x)))          #data(sccs)    
dep_var<-sccs$HiGod4                      #sccs$v238  if you start with
s <- data.frame(long = sccs$longitud, lat = sccs$latitude, name = sccs$sccsnum)
s2 <- s[with(s, order(name)), ]
#draws map
#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)
for(i in s2$name[-length(s2$name)]){
               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")
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")
for(i in s2$name[-length(s2$name)]){
       if(i%%6 == 1) text(s2$long[i], s2$lat[i],  s2$name[i], pos=2, col ="dark green")

text(s2$long[3], s2$lat[3], s2$name[3], pos=4, col ="dark green")

                            text(s2$long[1], s2$lat[1],  s2$name[1], pos=2, col ="dark green")
                            text(s2$long[31], s2$lat[31],  s2$name[31], pos=2, col ="white")
                            text(s2$long[37], s2$lat[37],  s2$name[37], pos=2, col ="dark green")
                            text(s2$long[42], s2$lat[42],  s2$name[42], pos=2, col ="dark green")
                            text(s2$long[51], s2$lat[51],  s2$name[51], pos=2, col ="dark green")
                            text(s2$long[53], s2$lat[53],  s2$name[53], pos=2, col ="dark green")
                            text(s2$long[66], s2$lat[66],  s2$name[66], pos=2, col ="dark green")
                            text(s2$long[81], s2$lat[81],  s2$name[81], pos=2, col ="dark green")
                            text(s2$long[105], s2$lat[105],  s2$name[105], pos=2, col ="dark green")
                            text(s2$long[120], s2$lat[120],  s2$name[120], pos=2, col ="dark green")
                            text(s2$long[121], s2$lat[121],  s2$name[121], pos=2, col ="white")
                            text(s2$long[123], s2$lat[123],  s2$name[123], pos=2, col ="dark green")
                            text(s2$long[139], s2$lat[139],  s2$name[139], pos=2, col ="white")
                            text(s2$long[133], s2$lat[133],  s2$name[133], pos=2, col ="dark green")
                            text(s2$long[186], s2$lat[186],  s2$name[186], pos=2, col ="dark green")

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=1, col ="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 ="red")
#now has drawn lines and Colored Numbers for HiGod4

# dev.copy(png,'myMap.png')