View source: R/densityToPolygon.R
densityToPolygon | R Documentation |
densityToPolygon
takes a kernel density estimate object (returned by stats::density) and turns this into x and y coordinates that then be plotted using R's polygon
function.
densityToPolygon(d)
|
a kernel density estimate object from the R function |
The function returns a list containing two numeric vectors named x
and y
. These are the x and y coordinates for the vertices of a polygon that can be plotted as a probability density function.
samples <- rnorm(1000) d <- density(samples) p <- densityToPolygon(d) m = max(d$y) plot(d, ylim = c(0, m*1.25), xlab = "Estimate", col = "white", main = "Hatch Probability (Sterile Mated)", ylab = "Density") polygon(p$x, p$y, col = "blue")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.