plotFuncs: Helper function to plot multiple functions

View source: R/plots.R

plotFuncsR Documentation

Helper function to plot multiple functions

Description

This function uses a loop over lines and points to plot multiple functions with different parameters into one plot.

Usage

plotFuncs(
  x,
  ...,
  support = getSupport(x),
  col = par("col"),
  pch = par("pch"),
  lty = par("lty"),
  lwd = par("lwd"),
  nEval = 1500,
  add = FALSE,
  xlim = getSupport1DPlottingLimits(support),
  ylim = NULL,
  xs = xL[!xL %in% X],
  xL = if (xlim[1] != xlim[2]) seq(xlim[1], xlim[2], length.out = nEval),
  X = getSupportAtoms(support),
  xlab = "x",
  ylab = "f(x)",
  close = FALSE
)

## S3 method for class 'BDataDensities'
plot(
  x,
  ...,
  support = getSupport(x),
  col = par("col"),
  pch = par("pch"),
  lty = par("lty"),
  lwd = par("lwd"),
  nEval = 1500,
  add = FALSE,
  xlim = getSupport1DPlottingLimits(support),
  ylim = NULL,
  xs = xL[!xL %in% X],
  xL = if (xlim[1] != xlim[2]) seq(xlim[1], xlim[2], length.out = nEval),
  X = getSupportAtoms(support),
  xlab = "x",
  ylab = expression(d * X/d * P),
  close = FALSE
)

## S3 method for class 'BDataLogDensities'
plot(
  x,
  ...,
  support = getSupport(x),
  col = par("col"),
  pch = par("pch"),
  lty = par("lty"),
  lwd = par("lwd"),
  nEval = 1500,
  add = FALSE,
  xlim = getSupport1DPlottingLimits(support),
  ylim = NULL,
  xs = xL[!xL %in% X],
  xL = if (xlim[1] != xlim[2]) seq(xlim[1], xlim[2], length.out = nEval),
  X = getSupportAtoms(support),
  xlab = "x",
  ylab = expression(ln(dX/d * P)),
  close = FALSE
)

## S3 method for class 'BDataPDFs'
plot(
  x,
  ...,
  support = getSupport(x),
  col = par("col"),
  pch = par("pch"),
  lty = par("lty"),
  lwd = par("lwd"),
  nEval = 1500,
  add = FALSE,
  xlim = getSupport1DPlottingLimits(support),
  ylim = NULL,
  xs = xL[!xL %in% X],
  xL = if (xlim[1] != xlim[2]) seq(xlim[1], xlim[2], length.out = nEval),
  X = getSupportAtoms(support),
  xlab = "x",
  ylab = expression(pdf(x) == d * X/d * lambda),
  close = FALSE
)

## S3 method for class 'BDataLogPDFs'
plot(
  x,
  ...,
  support = getSupport(x),
  col = par("col"),
  pch = par("pch"),
  lty = par("lty"),
  lwd = par("lwd"),
  nEval = 1500,
  add = FALSE,
  xlim = getSupport1DPlottingLimits(support),
  ylim = NULL,
  xs = xL[!xL %in% X],
  xL = if (xlim[1] != xlim[2]) seq(xlim[1], xlim[2], length.out = nEval),
  X = getSupportAtoms(support),
  xlab = "x",
  ylab = "f(x)",
  close = FALSE
)

Arguments

x

a list of functions to be plotted, naming to be compatible with plot. Alternatively it can be a single function or a list with a single function which gives a matrix of results, where the columns correspond to the arguments and the rows to the different results.

...

further arguments for plot

support

a Support object telling what to plot

col

a (vector of) plotting colors recycled over functions

pch

a (vector of) plotting chars recycled over functions used for the discrete support

lty

a (vector of) line types recycled over the functions used for the lines of the continuous support

lwd

a (vector of) line widths recycled over the function used for the lines of the continuous support

nEval

the number of discretization points for the continuous support

add

a boolean, if TRUE functions are added to an existing plot, if FALSE a new plot is generated.

xlim

the xlim of a new plot

ylim

the ylim of a new plot, if NULL it will be computed from the range of the functions.

xs

the discretization points for the continuous support

xL

candidates for the discretization points for the continuous part, unallowed points will be removed.

X

the points for the discrete part of the support

xlab

the label of the x-axis

ylab

the label of the y-axis

close

if TRUE the data is plotted in closed from (i.e. representing a measure of integral 1), if a numeric value, it is closed to this numeric value. (not yet implemented: if 0 the centered version is plotted), if FALSE, the functions are plotted as is. see [clo].

Value

invisible the results of the computation

  • x - the evaluation points for continuous evaluation

  • y - the evaluated values for the continuous evaluation, each function gets a column

  • X - the evaluation points for the discrete support

  • Y - the evaluated values for the discrete support, each function gets a column

Functions

  • plot(BDataDensities): plot method for BDataDensities

  • plot(BDataLogDensities): plot method for BDataLogDensities

  • plot(BDataPDFs): plot method for BDataPDFs

  • plot(BDataLogPDFs): plot method for BDataLogPDFs

See Also

Other Support: Support(), cdf2Support(), pdf2Support(), sample2Support()

Examples

plotFuncs(list(fx(sin(10*x)),fx(cos(10*x))),support=Support(0,pi,0:3),pch=2:3,col=2:3)
X = BDataPDFs(list(fx(dnorm(x,0,1)),fx(dnorm(x,0.3,0.5)),fx(dnorm(x,0,1.5))),
              basis=B2N01Basis5)
plot(X,col=2:4)
plot(as.BDataLogPDFs(X),col=2:4)
plot(as.BDataDensities(X),col=2:4)
plot(as.BDataLogDensities(X),col=2:4)


DistributionalDDA documentation built on Oct. 20, 2026, 5:06 p.m.