plot.Distribution: Plot Distribution Functions for a distr6 Object

View source: R/plot_distribution.R

plot.DistributionR Documentation

Plot Distribution Functions for a distr6 Object

Description

Six plots, which can be selected with fun are available for discrete and continuous univariate distributions: pdf, cdf, quantile, survival, hazard and cumulative hazard. By default, the first two are plotted side by side.

Usage

## S3 method for class 'Distribution'
plot(
  x,
  fun = c("pdf", "cdf"),
  npoints = 3000,
  plot = TRUE,
  ask = FALSE,
  arrange = TRUE,
  ...
)

Arguments

x

distr6 object.

fun

vector of functions to plot, one or more of: "pdf","cdf","quantile", "survival", "hazard", "cumhazard", and "all"; partial matching available.

npoints

number of evaluation points.

plot

logical; if TRUE (default), figures are displayed in the plot window; otherwise a data.table::data.table() of points and calculated values is returned.

ask

logical; if TRUE, the user is asked before each plot, see graphics::par().

arrange

logical; if TRUE (default), margins are automatically adjusted with graphics::layout() to accommodate all plotted functions.

...

graphical parameters, see details.

Details

The evaluation points are calculated using inverse transform on a uniform grid between 0 and 1 with length given by npoints. Therefore any distribution without an analytical quantile method will first need to be imputed with the FunctionImputation decorator.

The order that the functions are supplied to fun determines the order in which they are plotted, however this is ignored if ask is TRUE. If ask is TRUE then arrange is ignored. For maximum flexibility in plotting layouts, set arrange and ask to FALSE.

The graphical parameters passed to ... can either apply to all plots or selected plots. If parameters in par are prefixed with the plotted function name, then the parameter only applies to that function, otherwise it applies to them all. See examples for a clearer description.

Author(s)

Chengyang Gao, Runlong Yu and Shuhan Liu

See Also

lines.Distribution

Examples

## Not run: 
# Plot pdf and cdf of Normal
plot(Normal$new())

# Colour both plots red
plot(Normal$new(), col = "red")

# Change the colours of individual plotted functions
plot(Normal$new(), pdf_col = "red", cdf_col = "green")

# Interactive plotting in order - par still works here
plot(Geometric$new(),
  fun = "all", ask = TRUE, pdf_col = "black",
  cdf_col = "red", quantile_col = "blue", survival_col = "purple",
  hazard_col = "brown", cumhazard_col = "yellow"
)

# Return plotting structure
x <- plot(Gamma$new(), plot = FALSE)

## End(Not run)

distr6 documentation built on March 28, 2022, 1:05 a.m.