gstat icon indicating copy to clipboard operation
gstat copied to clipboard

Idea: the `plot.vgm()` function

Open Nowosad opened this issue 6 years ago • 6 comments

gstat allows for plotting of variograms, and of variograms with models. However, it could be also useful to have an option to plot just a model alone, for example when using uncoditional simulation or for teaching purposes.

library(gstat)
library(sp)
data(meuse)
coordinates(meuse) = ~x+y

# variogram plot ----------------------------------------------------------
vario = variogram(log(zinc)~1, meuse)
plot(vario)


# variogram + model plot --------------------------------------------------
model = vgm(0.6, "Sph", 1000, nugget = 0.06)
plot(vario, model)        


# model plot? -------------------------------------------------------------
plot(model, sill = 0.7, cutoff = 1600)

Nowosad avatar Jan 27 '19 10:01 Nowosad

As in

plot.variogramModel = function(x, ..., cutoff, type = 'l') {
    if (missing(cutoff))
        stop("parameter cutoff needs to be specified")
    plot(variogramLine(x, cutoff, ...), type = type)
}

?

edzer avatar Jan 27 '19 18:01 edzer

Yes, this is exactly what I had in mind. Tiny suggestions - (a) change the line color to light blue, (b) change x and y labels to "distance" and "semiwariance", and (c) start the plot from 0 on the x and y axes to follow the convention of the previous plots.

library(gstat)
plot.variogramModel = function(x, ..., cutoff, type = 'l') {
  if (missing(cutoff))
    stop("parameter cutoff needs to be specified")
  plot(variogramLine(x, cutoff, ...), type = type)
}

# model -------------------------------------------------------------
model = vgm(0.6, "Sph", 1000, nugget = 0.06)
plot(model, cutoff = 1600)

Created on 2019-01-28 by the reprex package (v0.2.1)

Nowosad avatar Jan 28 '19 10:01 Nowosad

I'll look into; it should be similar to plot.gstatVariogram (using lattice, setting the x axis minimum to 0); you're right about the axis labels.

edzer avatar Jan 28 '19 10:01 edzer

@edzer The function works great on a standard variogram. Could it also work on directional variograms?

library(gstat)

# model -------------------------------------------------------------
model = vgm(0.6, "Sph", 1000, nugget = 0.06)
plot(model, cutoff = 1600)


# directional model -------------------------------------------------
model2 = vgm(0.6, "Sph", 1000, nugget = 0.06, anis = c(45, 0.4))
plot(model2, cutoff = 1600)

Created on 2019-01-28 by the reprex package (v0.2.1)

Nowosad avatar Jan 28 '19 16:01 Nowosad

Yes, if you specify the direction vector:

> plot(model2, cutoff = 1600, dir = c(.5 *sqrt(2),.5* sqrt(2),0))
> plot(model2, cutoff = 1600, dir = c(.5 *sqrt(2), -.5* sqrt(2),0))

see ?variogramLine

edzer avatar Jan 28 '19 17:01 edzer

@edzer Would it be possible to add an alpha argument (like in, for example, variogram() function)?

Nowosad avatar Jan 29 '19 17:01 Nowosad