R: Methods for function 'plot' in package 'RandomFields'
plot-method
R Documentation
Methods for function plot in package RandomFields
Description
Plot methods are implemented for simulated random fields (objects of
class RFsp), explicit covariance models
(objects of class RMmodel),
empirical variograms (objects of class
RFempVariog) and fitted models
(objects of class RFfit).
The plot methods not described here are described together with the
class itself, for instance,
RFfit,
RFempVariogRMmodel.
Usage
RFplotSimulation(x, y, MARGIN=c(1,2), MARGIN.slices=NULL,
n.slices = if (is.null(MARGIN.slices)) 1 else 10, nmax=6,
plot.variance = !is.null(x@.RFparams$has.variance) && x@.RFparams$has.variance,
select.variables, zlim, legend=TRUE,
MARGIN.movie = NULL, file=NULL, speed = 0.3,
height.pixel=300, width.pixel=height.pixel,
..., plotmethod="image")
RFplotSimulation1D(x, y, nmax=6,
plot.variance=!is.null(x@.RFparams$has.variance) && x@.RFparams$has.variance,
legend=TRUE, ...)
## S4 method for signature 'RFgridDataFrame,missing'
plot(x, y, ...)
## S4 method for signature 'RFpointsDataFrame,missing'
plot(x, y, ...)
## S4 method for signature 'RFspatialGridDataFrame,missing'
plot(x, y, ...)
## S4 method for signature 'RFspatialPointsDataFrame,missing'
plot(x, y, ...)
## S4 method for signature 'RFgridDataFrame,matrix'
plot(x, y, ...)
## S4 method for signature 'RFpointsDataFrame,matrix'
plot(x, y, ...)
## S4 method for signature 'RFspatialGridDataFrame,matrix'
plot(x, y, ...)
## S4 method for signature 'RFspatialPointsDataFrame,matrix'
plot(x, y, ...)
## S4 method for signature 'RFgridDataFrame,data.frame'
plot(x, y, ...)
## S4 method for signature 'RFpointsDataFrame,data.frame'
plot(x, y, ...)
## S4 method for signature 'RFspatialGridDataFrame,data.frame'
plot(x, y, ...)
## S4 method for signature 'RFspatialPointsDataFrame,data.frame'
plot(x, y, ...)
## S4 method for signature 'RFgridDataFrame,RFgridDataFrame'
plot(x, y, ...)
## S4 method for signature 'RFgridDataFrame,RFpointsDataFrame'
plot(x, y, ...)
## S4 method for signature 'RFpointsDataFrame,RFgridDataFrame'
plot(x, y, ...)
## S4 method for signature 'RFpointsDataFrame,RFpointsDataFrame'
plot(x, y, ...)
## S4 method for signature 'RFspatialGridDataFrame,RFspatialGridDataFrame'
plot(x, y, ...)
## S4 method for signature 'RFspatialGridDataFrame,RFspatialPointsDataFrame'
plot(x, y, ...)
## S4 method for signature 'RFspatialPointsDataFrame,RFspatialGridDataFrame'
plot(x, y, ...)
## S4 method for signature 'RFspatialPointsDataFrame,RFspatialPointsDataFrame'
plot(x, y, ...)
## S4 method for signature 'RFspatialGridDataFrame'
persp(x, ..., zlab="")
## S3 method for class 'RFspatialGridDataFrame'
contour(x, ...)
Arguments
x
object of class RFsp or
RMmodel; in the latter case, x can
be any sophisticated model but it must be either stationary or a
variogram model
y
ignored in most methods
MARGIN
vector of two; two integer values giving the coordinate
dimensions
w.r.t. which the field or the covariance model
is to be plotted; in all other directions,
the first index is taken
MARGIN.slices
integer value; if [space-time-dimension>2],
MARGIN.slices can specify a third dimension w.r.t. which a
sequence of slices is plotted. Currently only works for grids.
n.slices
integer value.
The number of slices to be plotted; if
n.slices>1, nmax is set to 1. Or n.slices is a
vector of 3 elements: start, end, length. Currently only works for grids.
nmax
the maximal number of the x@.RFparams$n iid copies
of the field that are to be plotted
MARGIN.movie
integer. If given a sequence of figures is shown for this
direction. This option is in an experimental stage.
It works only for grids.
file, speed, height.pixel, width.pixel
In case MARGIN.movie and file is given an 'avi' movie
is stored using the mencoder command with speed argument
speed. As temporary files file__###.png
of size width.pixel x height.pixel are created.
...
arguments to be passed to methods; mainly graphical
arguments, or further models in case of class 'RMmodel',
see Details.
plot.variance
logical, whether variances should be plotted if
available
select.variables
vector of integers or list of vectors.
The argument is only of interest for multivariate models.
Here, length(select.variables) gives the number of pictures shown
(excuding the plot for the variances, if applicable).
If select.variables is a vector of integers then exactly these
components are shown. If select.variables is a list, each element
should be a vector up to length l <= 3:
l=1 the component is shown in the usual way
l=2 the two components are interpreted as vector and
arrows are plotted
l=3 the first component is shown as single component;
the remaining two component are interpreted as a vector and
plotted into the picture of the first component
legend
logical, whether a legend should be plotted
zlim
vector of length 2 with the usual meaning.
In case of multivariate random fields, zlim can also be a character
wih the value ‘joint’ indicating that all plotted compoments shall
have the same zlim OR a matrix with two rows, where the i-th column
gives the zlim of the i-th variable OR a list with entries named
data and var if a separate zlim
for the Kriging variance is to
be used.
plotmethod
string or function. Internal.
zlab
character. See persp
Details
Internally, ... are passed to image and
plot.default, respectively; if, by default, multiple colors,
xlabs or ylabs are used, also vectors of suitable length can be
passed as col, xlab and ylab, respectively.
One exception is the use of ... in plot for class
'RMmodel'.
Here, further models might be passed. All models must have names
starting with model. If '.' is following in the name,
the part of the name after the dot is shown in the legend. Otherwise
the name is ignored and a standardized name derived from the model
definition is shown in the legend. Note that for the first argument
a name cannot be specified.
Methods
signature(x = "RFspatialGridDataFrame", y =
"missing")
Generates nice image plots of simulation results for
simulation on a grid and space-time-dimension >1. If
space-time-dimension >2, plots are on 2-dimensional
subspaces.
Handles multivariate random fields (.RFparams$vdim>1) as well as
repeated iid simulations (.RFparams$vdim>n).
signature(x = "RFspatialGridDataFrame", y =
"RFspatialPointsDataFrame")
Similar to method for y="missing", but additionally adds the
points of y. Requires MARGIN.slices=NULL and
all.equal(x@.RFparams, y@.RFparams).
signature(x = "RFspatialGridDataFrame", y =
"matrix")
Similar to method for y="missing", but additionally adds the
points of y. Requires MARGIN.slices=NULL and
all.equal(x@.RFparams, y@.RFparams).
signature(x = "RFspatialPointsDataFrame", y =
"RFspatialGridDataFrame")
Throws an error. Probably x and y have been interchanged.
signature(x = "RFspatialPointsDataFrame", y =
"missing")
Similar to method for class
RFspatialGridDataFrame, but for non-gridded simulation results.
Instead of a grid, only existing points are plotted with colors indicating
the value of the random field at the respective location. Handles
multivariate random fields (.RFparams$vdim>1) as well as
repeated iid simulations (.RFparams$vdim>n).
signature(x = "RFspatialPointsDataFrame", y =
"RFspatialPointsDataFrame")
Similar to method for y="missing", but additionally adds the
points of y. Requires
all.equal(x@.RFparams, y@.RFparams).
signature(x = "RFgridDataFrame", y = "missing")
Generates
plots of simulation results for space-time-dimension =1.
Handles different values for the number of repetitions as well as
multivariate responses.
signature(x = "RFpointsDataFrame", y = "missing")
Similar
to method for class RFgridDataFrame, but for non-gridded data.
RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
## RFoptions(seed=NA) to make them all random again
## define the model:
model <- RMtrend(mean=0.5) + # mean
RMstable(alpha=1, var=4, scale=10) + # see help("RMstable")
## for additional arguments
RMnugget(var=1) # nugget
#############################################################
## Plot of covariance structure
plot(model)
plot(model, xlim=c(0, 30))
plot(model, xlim=c(0, 30), fct.type="Variogram")
plot(model, xlim=c(-10, 20), fct.type="Variogram", dim=2)
image(model, xlim=c(-10, 20), fct.type="Variogram")
persp(model, xlim=c(-10, 20), fct.type="Variogram")
#############################################################
## Plot of simulation results
## define the locations:
from <- 0
step <- .1
len <- 50 # nicer if len=100 %ok
x1D <- GridTopology(from, step, len)
x2D <- GridTopology(rep(from, 2), rep(step, 2), rep(len, 2))
x3D <- GridTopology(rep(from, 3), rep(step, 3), rep(len, 3))
## 1-dimensional
sim1D <- RFsimulate(model = model, x=x1D, n=6)
plot(sim1D, nmax=4)
## 2-dimensional
sim2D <- RFsimulate(model = model, x=x2D, n=6)
plot(sim2D, nmax=4)
plot(sim2D, nmax=4, col=terrain.colors(64),
main="My simulation", xlab="my_xlab")
## 3-dimensional
model <- RMmatern(nu=1.5, var=4, scale=2)
sim3D <- RFsimulate(model = model, x=x3D)
plot(sim3D, MARGIN=c(2,3), MARGIN.slices=1, n.slices=4)
#############################################################
## empirical variogram plots
x <- seq(0, 10, 0.05)
bin <- seq(from=0, by=.2, to=3)
model <- RMexp()
X <- RFsimulate(x=cbind(x), model=model)
ev1 <- RFempiricalvariogram(data=X, bin=bin)
plot(ev1)
model <- RMexp(Aniso = cbind(c(10,0), c(0,1)))
X <- RFsimulate(x=cbind(x,x), model=model)
ev2 <- RFempiricalvariogram(data=X, bin=bin, phi=3)
plot(ev2, model=list(exp = model))
#############################################################
## plot Fitting results
x <- seq(0, 1, len=21)
model <- RMexp(Aniso = cbind(c(10,0), c(0,1)))
X <- RFsimulate(x=cbind(x,x), model=model)
fit <- RFfit(~RMexp(Aniso=diag(c(NA, NA))), data=X, fit.nphi = 2,
modus="easygoing")
plot(fit)
#############################################################
## plot Kriging results
model <- RMwhittle(nu=1.2, scale=2)
n <- 200
x <- runif(n, max=step*len/2)
y <- runif(n, max=step*len/2) # 200 points in 2 dimensional space
sim <- RFsimulate(model = model, x=x, y=y)
interpolate <- RFinterpolate(model=model, x=x2D, data=sim)
plot(interpolate)
plot(interpolate, sim)
#############################################################
## plotting vector-valued results
model <- RMdivfree(RMgauss(), scale=4)
x <- y <- seq(-10,10, 0.5)
simulated <- RFsimulate(model = model, x=x, y=y, n=1)
plot(simulated)
plot(simulated, select.variables=list(1, 1:3, 4))
#############################################################
## options for the zlim argument
model <- RMdelay(RMstable(alpha=1.9, scale=2), s=c(0, 4)) +
RMdelay(RMstable(alpha=1.9, scale=2), s=c(4, 0))
simu <- RFsimulate(model, x, y)
plot(simu, zlim=list(data=cbind(c(-6,2), c(-2,1)), var=c(5,6)))
plot(simu, zlim=cbind(c(-6,2), c(-2,1)))
plot(simu, zlim=c(-6,2))
plot(simu, zlim="joint")
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(RandomFields)
Loading required package: sp
Loading required package: RandomFieldsUtils
This is RandomFieldsUtils Version: 0.2.1
This is RandomFields Version: 3.1.16
Attaching package: 'RandomFields'
The following object is masked from 'package:RandomFieldsUtils':
RFoptions
The following objects are masked from 'package:base':
abs, acosh, asin, asinh, atan, atan2, atanh, cos, cosh, exp, expm1,
floor, gamma, lgamma, log, log1p, log2, logb, max, min, round, sin,
sinh, sqrt, tan, tanh, trunc
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/RandomFields/plot-method.Rd_%03d_medium.png", width=480, height=480)
> ### Name: plot-method
> ### Title: Methods for function 'plot' in package 'RandomFields'
> ### Aliases: plot-method plot,RFgridDataFrame,missing-method
> ### plot,RFpointsDataFrame,missing-method
> ### plot,RFspatialGridDataFrame,missing-method
> ### plot,RFspatialPointsDataFrame,missing-method
> ### plot,RFgridDataFrame,matrix-method
> ### plot,RFpointsDataFrame,matrix-method
> ### plot,RFspatialGridDataFrame,matrix-method
> ### plot,RFspatialPointsDataFrame,matrix-method
> ### plot,RFgridDataFrame,data.frame-method
> ### plot,RFpointsDataFrame,data.frame-method
> ### plot,RFspatialGridDataFrame,data.frame-method
> ### plot,RFspatialPointsDataFrame,data.frame-method
> ### plot,RFgridDataFrame,RFgridDataFrame-method
> ### plot,RFgridDataFrame,RFpointsDataFrame-method
> ### plot,RFpointsDataFrame,RFgridDataFrame-method
> ### plot,RFpointsDataFrame,RFpointsDataFrame-method
> ### plot,RFspatialGridDataFrame,RFspatialGridDataFrame-method
> ### plot,RFspatialGridDataFrame,RFspatialPointsDataFrame-method
> ### plot,RFspatialPointsDataFrame,RFspatialGridDataFrame-method
> ### plot,RFspatialPointsDataFrame,RFspatialPointsDataFrame-method
> ### persp,RFspatialGridDataFrame-method contour.RFspatialGridDataFrame
> ### RFplotSimulation RFplotSimulation1D
> ### Keywords: methods
>
> ### ** Examples
>
> RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
> ## RFoptions(seed=NA) to make them all random again
> ## Don't show:
> StartExample()
> ## End(Don't show)
>
>
> ## define the model:
> model <- RMtrend(mean=0.5) + # mean
+ RMstable(alpha=1, var=4, scale=10) + # see help("RMstable")
+ ## for additional arguments
+ RMnugget(var=1) # nugget
>
>
> #############################################################
> ## Plot of covariance structure
>
> plot(model)
NULL
> plot(model, xlim=c(0, 30))
NULL
> plot(model, xlim=c(0, 30), fct.type="Variogram")
NULL
> plot(model, xlim=c(-10, 20), fct.type="Variogram", dim=2)
NULL
> image(model, xlim=c(-10, 20), fct.type="Variogram")
NULL
> persp(model, xlim=c(-10, 20), fct.type="Variogram")
NULL
>
> #############################################################
> ## Plot of simulation results
>
> ## define the locations:
> from <- 0
> step <- .1
> len <- 50 # nicer if len=100 %ok
> ## Don't show:
> if(RFoptions()$internal$examples_red){warning("reduced 'len'"); len<-3}
Warning message:
reduced 'len'
> ## End(Don't show)
> x1D <- GridTopology(from, step, len)
> x2D <- GridTopology(rep(from, 2), rep(step, 2), rep(len, 2))
> x3D <- GridTopology(rep(from, 3), rep(step, 3), rep(len, 3))
>
> ## 1-dimensional
> sim1D <- RFsimulate(model = model, x=x1D, n=6)
number of simulations reduced
NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
..
New output format of RFsimulate: S4 object of class 'RFsp';
for a bare, but faster array format use 'RFoptions(spConform=FALSE)'.
> plot(sim1D, nmax=4)
>
> ## 2-dimensional
> sim2D <- RFsimulate(model = model, x=x2D, n=6)
number of simulations reduced
NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
..
> plot(sim2D, nmax=4)
> plot(sim2D, nmax=4, col=terrain.colors(64),
+ main="My simulation", xlab="my_xlab")
>
> ## 3-dimensional
> model <- RMmatern(nu=1.5, var=4, scale=2)
> sim3D <- RFsimulate(model = model, x=x3D)
NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
> plot(sim3D, MARGIN=c(2,3), MARGIN.slices=1, n.slices=4)
>
>
> #############################################################
> ## empirical variogram plots
>
> x <- seq(0, 10, 0.05)
> bin <- seq(from=0, by=.2, to=3)
>
> model <- RMexp()
> X <- RFsimulate(x=cbind(x), model=model)
NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
> ev1 <- RFempiricalvariogram(data=X, bin=bin)
> plot(ev1)
>
> model <- RMexp(Aniso = cbind(c(10,0), c(0,1)))
> X <- RFsimulate(x=cbind(x,x), model=model)
NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
> ev2 <- RFempiricalvariogram(data=X, bin=bin, phi=3)
> plot(ev2, model=list(exp = model))
>
> #############################################################
> ## plot Fitting results
> x <- seq(0, 1, len=21)
>
> model <- RMexp(Aniso = cbind(c(10,0), c(0,1)))
> X <- RFsimulate(x=cbind(x,x), model=model)
NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
> fit <- RFfit(~RMexp(Aniso=diag(c(NA, NA))), data=X, fit.nphi = 2,
+ modus="easygoing")
Note that the option 'modus_operandi' is still in an experimental stage, so that the behaviour may change (slightly) in future.
> plot(fit)
>
>
> #############################################################
> ## plot Kriging results
> model <- RMwhittle(nu=1.2, scale=2)
> n <- 200
> x <- runif(n, max=step*len/2)
> y <- runif(n, max=step*len/2) # 200 points in 2 dimensional space
> sim <- RFsimulate(model = model, x=x, y=y)
NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
>
> interpolate <- RFinterpolate(model=model, x=x2D, data=sim)
> plot(interpolate)
> plot(interpolate, sim)
>
>
> #############################################################
> ## plotting vector-valued results
> model <- RMdivfree(RMgauss(), scale=4)
> x <- y <- seq(-10,10, 0.5)
> simulated <- RFsimulate(model = model, x=x, y=y, n=1)
NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
> plot(simulated)
> plot(simulated, select.variables=list(1, 1:3, 4))
>
>
>
> #############################################################
> ## options for the zlim argument
> model <- RMdelay(RMstable(alpha=1.9, scale=2), s=c(0, 4)) +
+ RMdelay(RMstable(alpha=1.9, scale=2), s=c(4, 0))
> simu <- RFsimulate(model, x, y)
NOTE: simulation is performed with fixed random seed 0.
Set 'RFoptions(seed=NA)' to make the seed arbitrary.
>
> plot(simu, zlim=list(data=cbind(c(-6,2), c(-2,1)), var=c(5,6)))
> plot(simu, zlim=cbind(c(-6,2), c(-2,1)))
> plot(simu, zlim=c(-6,2))
> plot(simu, zlim="joint")
>
> ## Don't show:
> FinalizeExample()
> ## End(Don't show)
>
>
>
>
>
>
> dev.off()
null device
1
>