You are on page 1of 2

07/12/2019 web1.sph.emory.edu/users/lwaller/book/ch8/db6.

################################################
# Empirical variograms with the gstat library
#

# Set path

path <- "c:/classes/spatial.class/data.breaks/"

# open library (You will need to add this library to R like


# you did with splancs). Once R is open go to the "Packages"
# menu and choose "Install package(s) from CRAN...", select
# "gstat" from the list.

library(gstat)

# R will say "Loading required package: lattice" but you don't


# need to do anything for this

# help.start() will open the html help files which contain


# examples.

# attach the data set 'meuse' (soil concentrations from the Meuse
# River flood plain near the village Stein). This data set is
# included in the 'gstat' library so it is available after you
# load the library.

data(meuse)

# see what's in it

names(meuse)

# We have x,y coordinates, concentrations for several metals,


# elevation (elev), distance to the river from some GIS grid
# calculations (dist), percentage
# organic matter (om), flood frequency class (ffreq), soil type
# (soil), land use (landuse), and distance to river in meters
# (dist.m)

# Make a 'bubble plot' of the cadmium data. Dots at (x,y), area of each
# dot identifies its concentrations.
#
# The first entry is the data frame (meuse) containing the x,y, and z values,
#
# "xcol", "ycol", "zcol" give the names of the x,y,z values (in quotes),
#
# "main" is the title for the plot
#
# "key.entries" identifies the cutoff values for circle sizes....basically
# gives the circle sizes to use.
#
#"maxsize" is the size of the biggest cirle.
# See helpfile for more options...

postscript(paste(path,"cadbubble.ps",sep=""),paper="letter",horiz=T)
bubble(meuse, xcol="x",ycol="y",zcol="cadmium",
maxsize = 2.5, main = "cadmium concentrations (ppm)",
key.entries = c(.5,1,2,4,8,16))
dev.off()

# Make a bubble plot of the zinc data.

postscript(paste(path,"zincbubble.ps",sep=""),paper="letter",horiz=T)
bubble(meuse, xcol="x", ycol="y", zcol="zinc",
main = "zinc concentrations (ppm)",
key.entries = 100 * c(1,2,4,8,16))
dev.off()

# Are the zinc values normally distributed?


web1.sph.emory.edu/users/lwaller/book/ch8/db6.r 1/2
07/12/2019 web1.sph.emory.edu/users/lwaller/book/ch8/db6.r

postscript(paste(path,"zincQQ.ps",sep=""),paper="letter",horiz=T)
par(mfrow=c(2,2))
hist(meuse$zinc)
qqnorm(meuse$zinc)

# log(zinc) normal?

hist(log(meuse$zinc))
qqnorm(log(meuse$zinc))
dev.off()

# Find empirical variogram for log(zinc) data

data(meuse)

# Call variogram command.

# This is a function with lots of options...to get the basic empirical


# variogram we set
#
# data=meuse to tell which data frame to use (so we don't have to put
# "meuse$" in front of the variable names)
#
# log(zinc)~1 is an R "equation" saying the outcome variable is "log(zinc)"
# and 1 implies an intercept-only model (constant mean assumption in
# intrinsic stationarity...)
#
# loc=~x+y defines the locations as just (x,y) coordinates

logzinc.var <- variogram(log(zinc)~1, loc=~x+y, data=meuse)

print(logzinc.var)

# This prints out the number of pairs (np)


# The average distance for point pairs with one of the point estimates (dist)
# The SEMIvariogram estimate (gamma)
# Directions horizontal and vertical (dir.hor, dir.ver)
# the combined id pair (id) (?????)

# Now plot them.

postscript(paste(path,"logzincvgram.ps",sep=""),paper="letter",horiz=T)
plot(logzinc.var)
dev.off()

web1.sph.emory.edu/users/lwaller/book/ch8/db6.r 2/2

You might also like