View source: R/plot_densities.R
JPlotDensities | R Documentation |
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.
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",
...
)
densities |
List of densities to be plotted |
lineColours |
Vector of colours used to draw the lines. Defaults to the
rainbow palette ( |
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 |
fillAngles |
If not NA (the default), slope of shading lines used to
fill polygons (passed as argument |
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 |
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 |
NULL
or, if means are displayed, vector of mean values (returned invisibly).
density
, rainbow
,
RColorBrewer::brewer.pal
, polygon
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.