Hi,
I think the only thing you need to change is the call to xyplot:
# So instead of "| identification" use groups = identification
xyplot(gamma ~ dist, groups = identification, sv_list,
panel = function(...) {
panel.xyplot(...) # points of the sample var
ret = variogramLine(model_list[[panel.number()]], maxdist =
max(sv_list$dist))
llines(ret$dist, ret$gamma, col = "red")
})
This example above doesn't illustrate this point clearly, but it should
work. You can choose to not show the sample variogram but only the
models, comment the line "panel.xyplot(...)" in the call to xyplot to do
this.
# So instead of "| identification" use groups = identification
xyplot(gamma ~ dist, groups = identification, sv_list,
panel = function(...) {
#panel.xyplot(...) # points of the sample var
ret = variogramLine(model_list[[panel.number()]], maxdist =
max(sv_list$dist))
llines(ret$dist, ret$gamma, col = "red")
})
cheers,
Paul
Laura Poggio schreef:
Thank you very much for the code, that helped me a lot to organise my
variograms objects!
Now what I am trying to get is a plot with all 100 variograms
overlapping, to show the spread due to simulations from a
distribution. Is this possible with the xyplot function?
Thank you very much!
Laura
2009/12/4 Paul Hiemstra <p.hiems...@geo.uu.nl
<mailto:p.hiems...@geo.uu.nl>>
Paul Hiemstra wrote:
Laura Poggio wrote:
Dear all,
I would like to plot 100 variograms on the same plot,
possibly using a loop.
At the moment I am using autofitVariogram in the package
Automap to fit the
variograms automatically.
I found some code calling the lattice package (
http://tolstoy.newcastle.edu.au/R/e7/help/09/06/0940.html),
but it is giving
some problems for high numbers of variograms.
Thank you very much in advance!
Laura
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
<mailto:R-sig-Geo@stat.math.ethz.ch>
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Hi Laura,
The trick is to organize your data, an example using the meuse
dataset:
library(lattice)
...and ofcourse you need to do:
library(automap)
# Make a dataset with 100 fitted variogram models
# Don't know how you've organized your 100 models,
# But I put them in a list.
data(meuse)
coordinates(meuse) =~ x+y
av_list = lapply(1:100, function(x) autofitVariogram(zinc~1,
meuse))
# Now extract the sample variograms, add an extra
# identification column to them and rbind them together
sv_list = do.call("rbind", lapply(1:length(av_list), function(x) {
sv = av_list[[x]]$exp_var
sv$identification = as.character(x)
return(sv)
}))
# Make a list of fitted models
model_list = lapply(av_list, function(x) x$var_model)
# Make the plot, notice the formula part!
# I use panel.number(), the current panel number,
# to extract the appropriate variogram model
xyplot(gamma ~ dist | identification, sv_list,
panel = function(...) {
panel.xyplot(...) # points of the sample var
ret = variogramLine(model_list[[panel.number()]], maxdist =
max(sv_list$dist))
llines(ret$dist, ret$gamma, col = "red")
})
cheers,
Paul
--
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 <http://intamap.geo.uu.nl/%7Epaul>
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo