Chapter 1: Code and Figures

R Code

All verbatim chunk codes used in the Chapter are available in hello.R


Figure 1.2

Click on figure to go back to Chapter gallery. Please see preceeding chunks for values not set in this chunk (hello-012.R).

def.par <- par(no.readonly = TRUE) = read.table("hsd_data/data1964al.xy")
volc = SpatialPoints([c(2,1)])
llCRS <- CRS("+proj=longlat +ellps=WGS84")
proj4string(volc) <- llCRS
prj_new = CRS("+proj=moll")
volc_proj = spTransform(volc, prj_new)
 wrld <- map("world", interior=FALSE, xlim=c(-179,179), ylim=c(-89,89), plot=FALSE)
 wrld_p <- pruneMap(wrld, xlim=c(-179,179))
 wrld_sp <- map2SpatialLines(wrld_p, proj4string=llCRS)
 wrld_proj <- spTransform(wrld_sp, prj_new)
 #save(c("wrld_proj", "wrld_sp"), file = "hsd_data/wrld.RData")
wrld_grd <- gridlines(wrld_sp, easts=c(-179,seq(-150,150,50),179.5), norths=seq(-75,75,15), ndiscr=100)
wrld_grd_proj <- spTransform(wrld_grd, prj_new)
at_sp <- gridat(wrld_sp, easts=0, norths=seq(-75,75,15), offset=0.3)
at_proj <- spTransform(at_sp, prj_new)
opar = par(no.readonly = TRUE)
par(mar=c(1,1,1,1)+0.1, xpd=NA)
plot(wrld_proj, col="grey50")
plot(wrld_grd_proj, add=TRUE, lty=3, col="grey50")
points(volc_proj, cex = .8, pch = 3)
text(coordinates(at_proj), pos=at_proj$pos, offset=at_proj$offset, labels=parse(text=as.character(at_proj$lab)), cex=0.6)
grey_gamma <- 2.2