ridgeplot | R Documentation |
ridgeplot
generates stacked density plots (aka. "ridge plots") in
the style of the package ggridge
, but using only base R graphics.
ridgeplot(
x,
xlim = NA,
labels = NA,
yaxt = "s",
xlab = NA,
ylab = NA,
step = 0.2,
col = NA,
fill = NA,
lwd = 1,
density.args = list(),
add.grid = F,
grid.args = list(),
extend.lines = T,
add = F,
freq = F,
prev = NA,
...
)
x: |
a list of numeric vectors, such as produced by calling split(). |
xlim: |
by default, automatically set to range of horizontal axis. |
labels: |
override names in list 'x' |
xlab: |
string to label x-axis (default NA) |
ylab: |
string to label y-axis (default NA) |
step: |
numeric value to determine spread and ordering of densities. Negative values cause reversed ordering. |
col: |
character vector of R colours for lines and borders. Will recycle colours if there are fewer than the number of groups in 'x'. |
fill: |
character vector of R colours for filling densities. Will recycle colours if there are fewer than the number of groups in 'x'. |
lwd: |
line width for drawing density curves and line segments. |
density.args: |
list of optional arguments for density(). |
add.grid: |
if TRUE, call add.grid() before drawing densities |
grid.args: |
list of optional arguments for add.grid() |
extend.lines: |
whether to draw densities across the horizontal range of plot. Defaults to TRUE. |
add: |
if TRUE, add the series of densities to existing plot. |
prev: |
numeric, factors to use in combination with add=TRUE to rescale heights of next set of densities |
freq: |
if TRUE, scale each ridgeplot in proportion to sample size. |
...: |
additional arguments for plot() |
ridgeplot(split(iris$Sepal.Length, iris$Species))
# reverse ordering, use solid colour lines and modify kernel density
ridgeplot(split(iris$Sepal.Length, iris$Species), step=-0.2,
col=c('firebrick', 'steelblue', 'olivedrab'), lwd=5,
density.args=list(n=20, kernel='rectangular', adjust=0.5))
# fill densities with translucent colours
require(RColorBrewer)
pal <- add.alpha(brewer.pal(3, 'Set1'), 0.5)
ridgeplot(split(iris$Sepal.Length, iris$Species), step=0.4, col='white',
fill=pal, lwd=2, xlab='Sepal length', cex.lab=1.2)
# passing arguments to add.grid()
ridgeplot(split(iris$Sepal.Length, iris$Species), step=0.4, col='white',
add.grid=T, grid.args=list(mode='y', bg.col='black', fg.col='grey',
lwd.major=0.5, lwd.minor=0))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.