2

It should be quite simple to adjust the font size in plotting the outcome ofautofitVariogram using the automap package. The text fonts for the number of pairs are too big; the text fonts for the model, nugget... information are too small and not presentable. I was able to adjust the size of the points, but I failed to adjust the font of the label (or remove them) and the model information.

I've tried:

library(automap)
data(meuse)
coordinates(meuse) <- c("x","y") 
data.auto.variogram <- autofitVariogram(formula = zinc ~1, input_data = meuse)
plot(data.auto.variogram, cex=1, par.settings=list(fontsize=list(text=5),par.main.text=list(cex=3), par.xlab.text=list(cex=2),par.ylab.text=list(cex=2)))

But that also reduces the size of the axis label and the information text.

We can use meuse as a reproducible example.

Can anyone give some solutions or recommendations please?

enter image description here

fdetsch
5,2332 gold badges32 silver badges42 bronze badges
asked Mar 31, 2017 at 1:01
10
  • Use par.settings option in the plot(). Commented Mar 31, 2017 at 9:00
  • I get no errors on the plot, but Error in text.default(data.auto.variogram$exp_var$dist, data.auto.variogram$exp_var$gamma, : plot.new has not been called yet on text(...). Commented Mar 31, 2017 at 10:42
  • Just tried plot(data.auto.variogram, par(cex.lab = 0.5)) but turns out Error in if (plotit) print(vario) else vario : argument is not interpretable as logical. Commented Apr 1, 2017 at 0:06
  • Do not use par(). To learn about par.settings, searching xyplot would be helpful. Commented Apr 1, 2017 at 2:28
  • Strange, I tried plot(data.auto.variogram,par.settings=list(cex.lab = 0.1)) but nothing's changed on the variogram. Commented Apr 1, 2017 at 3:24

1 Answer 1

2

The text size of bottom-right annotations is hard-coded in autokrige.vgm.panel.r, which runs under the hood of automap's plot() method. The latter function is also responsible for creating point labels that are passed to gstat::vgm.panel.xyplot(), which is hard-coded as well. Now, you might get rid of these point labels through something like

## sample data
library(automap)
data(meuse)
coordinates(meuse) <- ~ x + y
afv <- autofitVariogram(formula = zinc ~ 1, input_data = meuse)
p <- plot(afv, plotit = FALSE)
## discard point labels
library(lattice)
opts <- trellis.par.get()
opts$add.text$col <- "transparent"
update(p, par.settings = opts)

or, similarly, opts$add.text$cex to reduce text size. However, this won't affect the bottom-right text section. In order to overcome this limitation, why not just define your own plotting function for objects of class 'autofitVariogram'? Taking inspiration from the source code of autokrige.vgm.panel.r, this requires little coding efforts and, at the same time, lets you modify the visual appearance of the resulting scatter plot at will.

## create custom text annotation
dgt <- function(x) if (x >= 10) 0 else if (x >= 1) 1 else 2
mdl <- afv$var_model
cls <- as.character(mdl[2, "model"])
ngt <- sum(mdl[1, "psill"])
sll <- sum(mdl[, "psill"])
rng <- sum(mdl[, "range"])
lbl <- paste("Model:", cls,
 "\nNugget:", round(ngt, dgt(ngt)),
 "\nSill:", round(sll, dgt(sll)),
 "\nRange:", round(rng, dgt(rng)))
if (cls %in% c("Mat", "Ste")) {
 kpp <- mdl[2, "kappa"]
 lbl <- paste(lbl, "\nKappa:", round(kpp, dgt(kpp)), "")
}
## create plot
xyplot(gamma ~ dist, data = afv$exp_var,
 main = "Experimental variogram and fitted variogram model", 
 xlab = "Distance", ylab = "Semi-variance",
 panel = function(x, y, ...) {
 gstat::vgm.panel.xyplot(x, y, cex = 1.2, ...)
 ltext(max(x), 0.2 * max(y), lbl, font = 2, cex = .9, adj = c(1, 0), 
 col = "grey30")
 }, 
 # arguments required by gstat::vgm.panel.xyplot()
 labels = NULL, mode = "direct", model = mdl, 
 direction = c(afv$exp_var$dir.hor[1], afv$exp_var$dir.ver[1]))

variogram

answered Apr 6, 2017 at 11:31
2
  • Can you explain briefly dgt <- function(x) if (x >= 10) 0 else if (x >= 1) 1 else 2? Commented Aug 1, 2019 at 3:47
  • Absolutely. dgt() lets you control the number of displayed decimal places for nugget, sill, range, and kappa. Values >= 10 are rounded to the nearest integer; values >= 1 (but smaller than 10) have one decimal place as seen from kappa above; and smaller values have two decimal places. Commented Aug 1, 2019 at 15:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.