Description Usage Arguments Value References Examples
High density region (HDR) boxplots are a variation of boxplots. HDR plots are based on a density estimate of the marginal distribution.
Cutoff values for the probability are defined in the parameter probs
to define regions. In a uni-modal situation, the HDR plots with probability probs=0.25
show the boxes of a regular boxplot. The code is based on the hdrcde
package by Robert Hyndman (1996), who also introduced the plots.
1 2 3 4 5 6 |
mapping |
Set of aesthetic mappings created by |
data |
A data frame. If specified, overrides the default data frame defined at the top level of the plot. |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
other arguments passed on to
|
geom |
Use to override the default connection between
|
scale |
if "area" (default), all vases have the same area (before trimming the tails). If "count", areas are scaled proportionally to the number of observations. If "width", all vases have the same maximum width. |
na.rm |
If |
A data frame with additional columns:
xmin, xmax, ymin, ymax |
coordinates of the boxes specifying each density region. |
prob |
the probability at which the density is cut - as given in the function call. |
mode |
the mode of the density |
Rob J. Hyndman, Computing and Graphing Highest Density Regions, The American Statistician, Vol. 50, No. 2 (May, 1996), pp. 120-126.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | require(ggplot2)
data(diamonds)
gghdr(diamonds, color, price)
ggplot(data=diamonds, aes(x=color, y=price)) + geom_hdr(probs=c(0.9, .5, .25), alpha=0.5)
gghdr(diamonds, cut, price, probs=c(50,25,12.5, 6.25, 1), fill=cut) +
scale_fill_brewer(palette="Set1") +
scale_colour_brewer(palette="Set1")
p <- ggplot(mtcars, aes(factor(cyl), mpg))
p + geom_hdr()
p + geom_hdr(aes(fill=factor(..probs..)), probs=c(.5, .25, .125)) + scale_fill_brewer()
gghdr(mtcars, factor(cyl), mpg, probs=c(50,25,12.5))
qplot(factor(cyl), mpg, data = mtcars, geom = "hdr")
p + geom_hdr() + geom_jitter(height = 0)
p + geom_hdr() + coord_flip()
qplot(factor(cyl), mpg, data = mtcars, geom = "hdr") +
coord_flip()
# Add aesthetic mappings
# Note that hdrs are automatically dodged when any aesthetic is
# a factor
p + geom_hdr(aes(fill = cyl))
p + geom_hdr(aes(fill = factor(cyl)))
p + geom_hdr(aes(fill = factor(vs)))
p + geom_hdr(aes(fill = factor(am)))
# Set aesthetics to fixed value
p + geom_hdr(fill = "grey80", colour = "#3366FF")
qplot(factor(cyl), mpg, data = mtcars, geom = "hdr",
colour = I("#3366FF"))
x <- rnorm(2000)
group <- rep(1:20, 100)
y <- factor(rep(c(1,2),1000))
qplot(y,x,facets=~group, fill=factor(y), geom="hdr")
qplot(y,x,facets=~group, fill=factor(..probs..), geom="hdr") + scale_fill_brewer()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.