JPlotDensities: Plot a list of densities

View source: R/plot_densities.R

JPlotDensitiesR Documentation

Plot a list of densities

Description

Plots a list of densities (as created by density). Plotting is performed using base graphics. Each density is drawn as a line, and optionally filled. Fill colours may be easily made transparent by specifying a value for fillAlpha. Attempts to provide sensible defaults while allowing maximum flexibility.

Usage

JPlotDensities(
  densities,
  lineColours = NULL,
  lty = 1,
  lwd = 2,
  fillColours = NULL,
  fillAlpha = NA,
  fillDensities = NA,
  fillAngles = NA,
  meanLty = NA,
  xlim = NULL,
  ylim = NULL,
  ylab = "Density",
  add = FALSE,
  legendLabels,
  legendPos = "topleft",
  ...
)

Arguments

densities

List of densities to be plotted

lineColours

Vector of colours used to draw the lines. Defaults to the rainbow palette (rainbow).

lty

Line style used to draw the lines.

lwd

Line width used to draw the lines.

fillColours

Vector of colours to fill the density polygons. If not specified or NULL, the polygons are not filled.

fillAlpha

If not NA (the default), should be an alpha value between 0 and 1. The alpha of the fill colours are multiplied by this value.

fillDensities

If not NA (the default), density of shading lines used to fill polygons (passed as argument density to polygon).

fillAngles

If not NA (the default), slope of shading lines used to fill polygons (passed as argument angle to polygon).

meanLty

Line style used to draw vertical mean. NA (the default) means don't draw mean lines.

xlim

Defines the graphical extents of the x-axis. Defaults to include all the density lines.

ylim

Defines the graphical extents of the y-axis. Defaults to include all the density lines.

ylab

Y label, passed to plot.

add

If TRUE, the densities are added to an existing plot, otherwise a new plot is created.

legendLabels

Optional vector of characters. If specified, a legend will be added to the plot.

legendPos

Position of optional legend.

...

Additional parameters are passed to plot.

Value

NULL or, if means are displayed, vector of mean values (returned invisibly).

See Also

density, rainbow, RColorBrewer::brewer.pal, polygon

Examples

data <- list(
  normal = rnorm(100),
  uniform = runif(50),
  exponential = rexp(200))
densities <- lapply(data, density)
JPlotDensities(densities)
# Display legend
legend("topleft", c("Normal", "Uniform", "Exponential"), col = rainbow(3), lwd = 2)


JimMcL/JUtils documentation built on Nov. 7, 2024, 11:25 a.m.