This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @blank: transparent; | |
| @snow: #ffffff; | |
| @unused: #9a9a9a; | |
| @urban: #e2bf58; | |
| @agriculture: #91a487; | |
| @grass: #6b7e60; | |
| @forest: #46533f; | |
| @water: #37526d; | |
| Map { background-color:@water;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## =================================================================================== | |
| ## Title: Converting SPAM 2000 from CSV to NetCDF Format | |
| ## Project: SPAM | |
| ## Author: Bacou, Melanie <[email protected]> | |
| ## Date: April 11, 2013 | |
| ## =================================================================================== | |
| library(ncdf) | |
| library(reshape2) | |
| library(data.table) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| setwd("/home/projects") | |
| library(data.table) | |
| library(rgdal) | |
| library(rgeos) | |
| library(maptools) | |
| library(stringr) | |
| # Load GAUL 2008 (release 2009) adm-2 from Darby | |
| g <- readOGR("./maps/admin", "g2008_2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Using read.dta() to load a sample STATA data file | |
| dta <- read.dta("my_toy_data.dta") | |
| # Let's describe dta | |
| str(dta) | |
| #'data.frame': 95202 obs. of 13 variables: | |
| # $ hh : num 1.01e+09 1.01e+09 1.01e+09 1.01e+09 1.01e+09 ... | |
| #$ h14aq2 : Factor w/ 61 levels "matooke","matooke",..: 50 51 34 47 57 41 22 1 13 53 ... | |
| #$ h14aq3 : Factor w/ 93 levels "Kilogram (kg)",..: 51 26 85 1 NA 1 55 70 1 33 ... | |
| #$ h14aq4 : num 0.5 4 4 1 NA 1.5 5 3 4 10 ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '(org-export-html-preamble-format (quote (("en" "<script type=\"text/javascript\"> | |
| function rpl(expr,a,b) { | |
| var i=0 | |
| while (i!=-1) { | |
| i=expr.indexOf(a,i); | |
| if (i>=0) { | |
| expr=expr.substring(0,i)+b+expr.substring(i+a.length); | |
| i+=b.length; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(rgdal) | |
| dsn="PG:dbname='gis'" | |
| # What tables are in that database? | |
| ogrListLayers(dsn) | |
| # [1] "ccsm_polygons" "nongp" "WrldTZA" | |
| # [4] "nongpritalin" "ritalinmerge" "metforminmergev" | |
| # Get one: | |
| polys = readOGR(dsn="PG:dbname='gis'","ccsm_polygons") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Example procedure for working with data (attributes) inside SpatialPolygonsDataFrame objects | |
| # Load my favorite libraries for that sort of work | |
| library(data.table) | |
| library(rgdal) | |
| # Load 2 shapefiles that, say, we want to merge. | |
| # Note that you can read pretty much any spatial format using readOGR(). | |
| tza.l2 <- readOGR("./analysis/TZA-AC-07/maps", "tza-ac-07_L2") | |
| tza.l1 <- readOGR("./analysis/TZA-AC-07/maps", "tza-ac-07_L1") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| spplot(g08[g08$ADM0_NAME=="Malawi",], "toba_dens", at=qtl, lwd=.6, cex=.7, | |
| xlab=NULL, ylab=NULL, col="gray57", | |
| col.regions=c("white", 37:28), | |
| main=list("Tobacco by District (kg/ha), Tanzania 2007/08", cex=.9)) + | |
| layer(sp.polygons(g08, col="gray40", fill=0, lwd=.5)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| latex(ex1[, -c(1:3)], | |
| booktabs=TRUE, file="", center="none", table.env=FALSE, | |
| rowname=paste(ex1$variable, ex1$unit, sep=" -- "), | |
| cgroup=c("Farming Systems"), n.cgroup=dim(ex1)[2]-3, | |
| rgroup=unique(ex1$AEZ5_CLAS), n.rgroup=rep(2, length(unique(ex1$AEZ5_CLAS)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gfmTable <- function(x, ...) { | |
| require(ascii) | |
| y <- capture.output(print(ascii(x, ...), type="org")) | |
| y <- gsub("-+-", "-|-", y, fixed=T) | |
| return(writeLines(y)) | |
| } |