Giorgio Gosti drawPath.R
From InterSciWiki
Revision as of 07:53, 22 October 2011 by Douglas R. White (Talk | contribs)
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 http://cran.r-project.org/web/packages/maps/maps.pdf --- http://cran.r-project.org/web/packages/mapdata/index.html
- http://pinard.progiciels-bpi.ca/libR/library/maps/html/world.html
- http://www.evl.uic.edu/pape/data/Earth/
- http://grass.osgeo.org/wiki/Global_datasets
- http://geography.uoregon.edu/geogr/topics/maps.htm
- http://geography.uoregon.edu/GeogR/examples/maps_examples02.htm
- http://r.789695.n4.nabble.com/Projecting-data-on-a-world-map-using-long-lat-td3081298.html
- http://www.ngdc.noaa.gov/mgg/shorelines/shorelines.html
- http://www.shadedrelief.com/cleantopo2/
setwd('/Users/drwhite/Documents/3sls/sccs/')
#source("Longi.R")
#source("Lati.R")
load(latlon,file='latlon.Rdata')
plot(long,lati, cex=.1)
lat<-sccs$v833.1
lon<-sccs$v833.2
#plot(lon,lat, cex=.1)
z=sccs$HiGod4
ztxt=as.character(z)
# text(lon,lat,ztxt)
#----------------------------------------------------------------
#This file works only if in the same folder of 'comb.RData'
#-----------------------------------------------------------
install.library(maps)
#loads data
load('comb.RData')
sccs<-data.frame(sapply(comb,function(x) as.numeric(x))) #data(sccs)
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 = "blue")
#grid()
# 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")
}
}
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")
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=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.copy2pdf() # dev.copy(png,'myMap.png') # dev.off()
