plotPolygonDensity | R Documentation |
Plot distribution and histogram overlay
plotPolygonDensity(
x,
doHistogram = TRUE,
doPolygon = TRUE,
col = NULL,
barCol = "#00337799",
polyCol = "#00449977",
polyBorder = makeColorDarker(polyCol),
histBorder = makeColorDarker(barCol, darkFactor = 1.5),
colAlphas = c(0.8, 0.6, 0.9),
darkFactors = c(-1.3, 1, 3),
lwd = 2,
las = 2,
u5.bias = 0,
pretty.n = 10,
bw = NULL,
breaks = 100,
width = NULL,
densityBreaksFactor = 3,
axisFunc = axis,
bty = "l",
cex.axis = 1.5,
doPar = TRUE,
heightFactor = 0.95,
weightFactor = NULL,
main = "Histogram distribution",
xaxs = "i",
yaxs = "i",
xaxt = "s",
yaxt = "s",
xlab = "",
ylab = "",
log = NULL,
xScale = c("default", "log10", "sqrt"),
usePanels = TRUE,
useOnePanel = FALSE,
ablineV = NULL,
ablineH = NULL,
ablineVcol = "#44444499",
ablineHcol = "#44444499",
ablineVlty = "solid",
ablineHlty = "solid",
removeNA = TRUE,
add = FALSE,
ylimQuantile = 0.99,
ylim = NULL,
xlim = NULL,
highlightPoints = NULL,
highlightCol = "gold",
verbose = FALSE,
...
)
x |
|
doHistogram |
|
doPolygon |
|
col |
|
barCol , polyCol , polyBorder , histBorder |
|
colAlphas |
|
darkFactors |
|
lwd |
|
las |
|
u5.bias , pretty.n |
|
bw |
|
breaks |
|
width |
|
densityBreaksFactor |
|
axisFunc |
|
bty |
|
cex.axis |
|
doPar |
|
heightFactor |
|
weightFactor |
|
main |
|
xaxs , yaxs , xaxt , yaxt |
|
xlab , ylab |
|
log |
|
xScale |
|
usePanels |
|
useOnePanel |
|
ablineV , ablineH |
|
ablineVlty , ablineHlty |
|
removeNA |
|
add |
|
ylimQuantile |
|
ylim , xlim |
|
highlightPoints |
|
highlightCol |
|
verbose |
|
... |
additional arguments are passed to relevant internal functions. |
This function is a wrapper around graphics::hist()
and
stats::density()
, with enough customization to cover
most of the situations that need customization.
For example log="x"
will automatically log-transform the x-axis,
keeping the histogram bars uniformly sized. Alternatively,
xScale="sqrt"
will square root transform the data, and
transform the x-axis while keeping the numeric values constant.
It also scales the density profile height to be similar to the histogram bar height, using the 99th quantile of the y-axis value, which helps prevent outlier peaks from dominating the y-axis range, thus obscuring interesting smaller features.
If supplied with a data matrix, this function will create a layout
with ncol(x)
panels, and plot the distribution of each column
in its own panel, using categorical colors from
colorjam::rainbowJam()
.
For a similar style using ggplot2, see plotRidges()
, which displays
only the density profile for each sample, but in a much more scalable
format for larger numbers of columns.
By default NA values are ignored, and the distributions represent non-NA values.
Colors can be controlled using the parameter col
, but can
be specifically defined for bars with barCol
and the polygon
with polyCol
.
invisible list
with density and histogram data output,
however this function is called for the by-product of its plot
output.
Other jam plot functions:
adjustAxisLabelMargins()
,
coordPresets()
,
decideMfrow()
,
drawLabels()
,
getPlotAspect()
,
groupedAxis()
,
imageByColors()
,
imageDefault()
,
minorLogTicksAxis()
,
nullPlot()
,
plotRidges()
,
plotSmoothScatter()
,
shadowText_options()
,
shadowText()
,
showColors()
,
smoothScatterJam()
,
sqrtAxis()
,
usrBox()
# basic density plot
set.seed(123);
x <- rnorm(2000);
plotPolygonDensity(x, main="basic polygon density plot");
# fewer breaks
plotPolygonDensity(x,
breaks=20,
main="breaks=20");
# log-scaled x-axis
plotPolygonDensity(10^(3+rnorm(2000)), log="x",
breaks=50,
main="log-scaled x-axis");
# highlighted points
set.seed(123);
plotPolygonDensity(x,
highlightPoints=sample(which(abs(x) > 1), size=200),
breaks=40,
main="breaks=40");
# hide axis labels
set.seed(123);
plotPolygonDensity(x,
highlightPoints=sample(which(abs(x) > 1), size=200),
breaks=40,
xaxt="n",
yaxt="n",
main="breaks=40");
# multiple columns
set.seed(123);
xm <- do.call(cbind, lapply(1:4, function(i){rnorm(2000)}))
plotPolygonDensity(xm, breaks=20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.