| plot_fxy | R Documentation |
Plot a real-valued function f evaluated on a grid of points
of the Cartesian plane, possibly with parameters specified by ....
The type of graphical display can be regulated by selecting the plotting
function among a set of available options.
plot_fxy(f, xlim, ylim, ..., npt=51, grf, grpar)
f |
either a function or a character string with the name of a
real-valued function whose first argument represents the
coordinates of points where |
xlim |
either a vector of abscissae where the |
ylim |
either a vector of ordinates where the |
... |
additional parameters to be supplied to |
npt |
either an integer value or a two-element integer vector with
the number of equally-spaced points, within the endpoints of |
grf |
an optional character string with the name of the function
which produces the graphical display, selectable among
|
grpar |
an optional character string with arguments supplied to the
selected |
Function f will be called with the first argument represented by a
two-column matrix, where each row represents a point of the grid on the
Cartesian plane identified by xlim and ylim;
this set of coordinates is stored in matrix pts of the returned list.
If present, arguments supplied as ... are also passed to f.
It is assumed that f accepts this type of call.
The original motivation of plot_fxy was to plot instances of bivariate
probability density functions specified by package mnormt,
but it can be used for plotting any function fulfilling the above requirements,
as illustrated by some of the examples below.
an invisible list with the following components:
x | a vector of coordinates on the x axis |
y | a vector of coordinates on the y axis |
pts | a matrix of dimension (npt[1]*npt[2],2)
with the coordinates of the evaluation points (x,y) |
f.values | the vector of f values at the pts points.
|
contour, filled.contour,
persp, image
Sigma <- matrix(c(1,1,1,2), 2, 2)
mean <- c(0, -1)
xlim <- c(-3, 5)
ylim <- c(-5, 3)
#
# multivariate normal density, contour-level plot
gp <- 'col="blue", nlevels=6, main="bivariate normal density"'
u <- plot_fxy(dmnorm, xlim, ylim, mean=mean, varcov=Sigma, grpar=gp)
cat(str(u))
#---
# multivariate normal density, filled-contour plot
plot_fxy(dmnorm, xlim, ylim, mean=mean, varcov=Sigma,grf="filled.contour")
#---
# multivariate normal density, perspective plot
gp <- "theta = 10, phi = 25, r = 2.5"
plot_fxy(dmnorm, xlim, ylim, mean=mean, varcov=Sigma, grf="persp", grpar=gp)
#---
# multivariate Student's "t" density;
# the xlim argument passed to function 'grf' overrides the earlier xlim;
# xlim and ylim can be placed after the arguments of 'f', if one prefers so
grp <- 'xlim=c(-1, 3)'
plot_fxy(dmt, mean=mean, S=Sigma, df=8, xlim, ylim, npt=101,
grf="filled.contour", grpar=grp)
#---
# multivariate truncated normal density, 'image' plot
low <- c(-3, -5)
hi <- c(1, 0)
plot_fxy(dmtruncnorm, mean=mean, varcov=Sigma, lower=low, upper=hi,
xlim, ylim, npt=81, grf="image")
#---
# multivariate truncated normal distribution function, 'image' plot;
# hence not a density function
low <- c(-3, -5)
hi <- c(1, 0)
v <- plot_fxy(pmtruncnorm, mean=mean, varcov=Sigma, lower=low, upper=hi,
xlim, ylim, npt=c(61, 81), grf="image")
#---
# a different sort of 'f' function (lbeta), not a component of this package
funct <- function(z) lbeta(a=z[,1], b=z[,2])
plot_fxy(funct, xlim=c(0.1, 2), ylim=c(0.1, 2), npt=41,
grpar='main="function log-beta(a,b)", xlab="a", ylab="b"')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.