Multiple variograms in one graph
Hi,
...or alternatively using the trellis plot system:
library(gstat)
library(lattice)
data(meuse)
coordinates(meuse)=~x+y
v1 = variogram(log(zinc)~1,meuse)
v2 = variogram(log(cadmium)~1,meuse)
m1 = fit.variogram(v1, vgm(1, "Sph", 800, 1))
m2 = fit.variogram(v2, vgm(1, "Sph", 800, 1))
# Arrange the data for the trellis plot
# add the semivariance values of v2 to v1
v1$gammaV2 = v2$gamma
# Construct the plot
xyplot(gamma + gammaV2 ~ dist, v1,
panel = function(...) {
panel.xyplot(..., col = c("red","blue"))
# First variogram model
ret = variogramLine(m1, maxdist = max(v1$dist))
llines(x = ret$dist, y = ret$gamma, col = "red", lty = 1)
# Second variogram model
ret = variogramLine(m2, maxdist = max(v2$dist))
llines(x = ret$dist, y = ret$gamma, col = "blue", lty = 1)
},
ylab = "semivariance",
xlab = "distance")
This is a bit more work than what Edzer suggested, but this solution is
much more flexible. For example if you have not only two variograms at
the same time, but also several times at which there are variograms. In
addition, xyplot takes care of the x and y limits automatically. Like
often in R, you can do stuff in several different ways.
cheers,
Paul
Edzer Pebesma wrote:
ageel bushara wrote:
Dear all,
?
I???m a new user of R. I
have two plots of variograms. Each plot shows the experimental variograms with its
fitted theoretical variograms. I would like to have the two plots in one graph
(all experimental and theoretical variograms will be in one graph). How can I
do it?
easiest to use basic plot: library(gstat) data(meuse) coordinates(meuse)=~x+y v1 = variogram(log(zinc)~1,meuse) v2 = variogram(log(cadmium)~1,meuse) m1 = fit.variogram(v1, vgm(1, "Sph", 800, 1)) m2 = fit.variogram(v2, vgm(1, "Sph", 800, 1)) plot(gamma~dist, v2, ylim = c(0, 1.05*max(v2$gamma)),col='red', ylab = 'semivariance', xlab = 'distance') lines(variogramLine(m2, 1500), col='red') points(gamma~dist, v1, col='blue') lines(variogramLine(m1, 1500), col='blue')
?
Thanks,
Ageel
[[alternative HTML version deleted]]
------------------------------------------------------------------------
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul