Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

plotDistr

Plot a probability density, mass, or distribution function.


Description

This function plots a probability density, mass, or distribution function, adapting the form of the plot as appropriate.

Usage

plotDistr(x, p, discrete=FALSE, cdf=FALSE, 
  regions=NULL, col="gray", 
  legend=TRUE, legend.pos="topright", ...)

Arguments

x

horizontal coordinates

p

vertical coordinates

discrete

is the random variable discrete?

cdf

is this a cumulative distribution (as opposed to mass) function?

regions, col

for continuous distributions only, if non-NULL, a list of regions to fill with color col; each element of the list is a pair of x values with the minimum and maximum horizontal coordinates of the corresponding region; col may be a single value or a vector.

legend

plot a legend of the regions (default TRUE).

legend.pos

position for the legend (see legend, default "topright").

...

arguments to be passed to plot.

Value

Produces a plot; returns NULL invisibly.

Author(s)

Examples

x <- seq(-4, 4, length=100)
plotDistr(x, dnorm(x), xlab="Z", ylab="p(z)", main="Standard Normal Density")
plotDistr(x, dnorm(x), xlab="Z", ylab="p(z)", main="Standard Normal Density",
    region=list(c(1.96, Inf), c(-Inf, -1.96)), col=c("red", "blue"))
plotDistr(x, dnorm(x), xlab="Z", ylab="p(z)", main="Standard Normal Density",
    region=list(c(qnorm(0), qnorm(.025)), c(qnorm(.975), qnorm(1)))) # same 

x <- 0:10
plotDistr(x, pbinom(x, 10, 0.5), xlab="successes", 
    discrete=TRUE, cdf=TRUE,
    main="Binomial Distribution Function, p=0.5, n=10")

RcmdrMisc

R Commander Miscellaneous Functions

v2.7-1
GPL (>= 2)
Authors
John Fox [aut, cre], Robert Muenchen [ctb], Dan Putler [ctb]
Initial release
2020-08-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.