Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: the plot.vgm() function #40

Open
Nowosad opened this issue Jan 27, 2019 · 6 comments
Open

Idea: the plot.vgm() function #40

Nowosad opened this issue Jan 27, 2019 · 6 comments

Comments

@Nowosad
Copy link

Nowosad commented Jan 27, 2019

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)
@edzer
Copy link
Member

edzer commented Jan 27, 2019

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)
}

?

@Nowosad
Copy link
Author

Nowosad commented Jan 28, 2019

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)

@edzer
Copy link
Member

edzer commented Jan 28, 2019

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 added a commit that referenced this issue Jan 28, 2019
@Nowosad
Copy link
Author

Nowosad commented Jan 28, 2019

@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)

@edzer
Copy link
Member

edzer commented Jan 28, 2019

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

@Nowosad
Copy link
Author

Nowosad commented Jan 29, 2019

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

@Nowosad Nowosad mentioned this issue Feb 5, 2019
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants