Title: | Visualisation of Highest Density Regions in 'ggplot2' |
---|---|
Description: | Provides 'ggplot2' framework for visualising Highest Density Regions (HDR) <doi:10.1080/00031305.1996.10474359>. This work is based on the package 'hdrcde'<https://pkg.robjhyndman.com/hdrcde/> and displays highest density regions in 'ggplot2' for one and two dimensions and univariate densities conditional on one covariate. |
Authors: | Mitchell O'Hara-Wild [aut] , Stephen Pearce [aut] , Ryo Nakagawara [aut], Sayani Gupta [aut, cre] , Darya Vanichkina [aut] , Emi Tanaka [aut] , Thomas Fung [aut] , Rob Hyndman [aut] |
Maintainer: | Sayani Gupta <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0.9000 |
Built: | 2024-11-04 19:54:24 UTC |
Source: | https://github.com/Sayani07/gghdr |
Provides 'ggplot2' framework for visualising Highest Density Regions (HDR) <doi:10.1080/00031305.1996.10474359>. This work is based on the package 'hdrcde'<https://pkg.robjhyndman.com/hdrcde/> and displays highest density regions in 'ggplot2' for one and two dimensions and univariate densities conditional on one covariate.
Maintainer: Sayani Gupta [email protected] (ORCID)
Authors:
Mitchell O'Hara-Wild [email protected] (ORCID)
Stephen Pearce (ORCID)
Ryo Nakagawara [email protected]
Darya Vanichkina [email protected] (ORCID)
Emi Tanaka [email protected] (ORCID)
Thomas Fung [email protected] (ORCID)
Rob Hyndman [email protected] (ORCID)
Useful links:
draw legend key for HDR box plot
draw_key_hdr_boxplot(data, params, size)
draw_key_hdr_boxplot(data, params, size)
data |
data |
params |
parameters |
size |
size of legend key |
Example dataframe for gghdr
data(faithful)
data(faithful)
This contains the 'Old Faithful Geyser' data used in the examples in README and vignettes.
The variables are as follows:
eruptions. Eruption time in mins
waiting. Waiting time to next eruption in mins
Box plot for the highest density region
geom_hdr_boxplot( mapping = NULL, data = NULL, stat = "hdrcde", position = "dodge2", ..., varwidth = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, prob = c(0.5, 0.95, 0.99) )
geom_hdr_boxplot( mapping = NULL, data = NULL, stat = "hdrcde", position = "dodge2", ..., varwidth = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, prob = c(0.5, 0.95, 0.99) )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
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. |
... |
Other arguments passed on to |
varwidth |
width, Default: FALSE |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
prob |
Probability coverage required for HDRs, Default: c(0.5, 0.95, 0.99) |
Calculates and plots the box plot of highest density regions.
A [ggplot2::Geom] representing a highest density region box plot geometry which can be added to a [ggplot()] object.
library(ggplot2) ggplot(faithful, aes(y = eruptions)) + geom_hdr_boxplot() ggplot(faithful, aes(y = eruptions, x= waiting)) + geom_hdr_boxplot(fill="steelblue")
library(ggplot2) ggplot(faithful, aes(y = eruptions)) + geom_hdr_boxplot() ggplot(faithful, aes(y = eruptions, x= waiting)) + geom_hdr_boxplot(fill="steelblue")
rug visualization for HDR plot
geom_hdr_rug( mapping = NULL, data = NULL, stat = "hdr", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, sides = "bl", rug_width = unit(0.03, "npc"), prob = c(0.5, 0.95, 0.99) )
geom_hdr_rug( mapping = NULL, data = NULL, stat = "hdr", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, sides = "bl", rug_width = unit(0.03, "npc"), prob = c(0.5, 0.95, 0.99) )
mapping |
Default: NULL |
data |
data |
stat |
stat |
position |
Default: "identity" |
... |
... |
na.rm |
Default: FALSE |
show.legend |
Default: NA |
inherit.aes |
Default: TRUE |
sides |
position to put rugs |
rug_width |
width of rugs, Default: unit(0.03, "npc") |
prob |
PARAM_DESCRIPTION, Default: c(0.5, 0.95, 0.99) |
Calculates and plots the rug plot of highest density regions.
library(ggplot2) ggplot(faithful, aes(x = waiting, y = eruptions)) + geom_point() + geom_hdr_rug()
library(ggplot2) ggplot(faithful, aes(x = waiting, y = eruptions)) + geom_point() + geom_hdr_rug()
The guide shows the colour scales mapped to different probability coverage required for HDRs
guide_prob(title = waiver(), ...)
guide_prob(title = waiver(), ...)
title |
A character string or expression indicating a title of guide.
If |
... |
Further arguments passed onto either
|
A guide object
Binning highest density regions in one or two dimensions
hdr_bin(x, y = NULL, prob = c(0.5, 0.9, 0.99), ...)
hdr_bin(x, y = NULL, prob = c(0.5, 0.9, 0.99), ...)
x |
Numeric vector |
y |
Numeric vector of same length as x. |
prob |
Probability coverage required for HDRs |
... |
... |
probability coverage for each element of the numeric vectors.
library(ggplot2) ggplot(data = faithful, aes(x = waiting, y = eruptions)) + geom_point(aes(colour = hdr_bin(x = waiting, y = eruptions)))
library(ggplot2) ggplot(data = faithful, aes(x = waiting, y = eruptions)) + geom_point(aes(colour = hdr_bin(x = waiting, y = eruptions)))
Example dataframe for gghdr
data(lane2)
data(lane2)
This contains the 'lane2' data from the 'hdrcde' package and is used in the examples in README and vignettes.
The variables are as follows:
flow. a numeric vector giving the traffic flow in vehicles per lane per hour
speed. a numeric vector giving he speed in miles per hour
This set of scales defines new scales for prob geometries equivalent to the ones already defined by ggplot2. This allows the shade of confidence intervals to work with the legend output.
scale_prob_identity(..., guide = "prob")
scale_prob_identity(..., guide = "prob")
... |
Arguments passed on to
|
guide |
Type of legend. Use |
A ggproto object inheriting from '[ggplot2::Scale]'
calculate components of hdr box and rug plot
stat_hdr( mapping = NULL, data = NULL, geom = "hdr_rug", position = "dodge2", ..., coef = 1.5, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
stat_hdr( mapping = NULL, data = NULL, geom = "hdr_rug", position = "dodge2", ..., coef = 1.5, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Default: NULL |
data |
Default: NULL |
geom |
PARAM_DESCRIPTION, Default: 'hdr_boxplot' |
position |
PARAM_DESCRIPTION, Default: 'dodge2' |
... |
... |
coef |
Default: 1.5 |
na.rm |
Default: FALSE |
show.legend |
Default: NA |
inherit.aes |
Default: TRUE |
A [ggplot2::Stat] representing the data transformations with required mappings for plotting HDRs using [geom_hdr_boxplot()] and [geom_hdr_rug()].
compute highest density regions continuously over some conditioned variable
stat_hdrcde( mapping = NULL, data = NULL, geom = "hdr_boxplot", position = "dodge2", ..., coef = 1.5, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
stat_hdrcde( mapping = NULL, data = NULL, geom = "hdr_boxplot", position = "dodge2", ..., coef = 1.5, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Default: NULL |
data |
Default: NULL |
geom |
PARAM_DESCRIPTION, Default: 'hdr_boxplot' |
position |
PARAM_DESCRIPTION, Default: 'dodge2' |
... |
... |
coef |
Default: 1.5 |
na.rm |
Default: FALSE |
show.legend |
Default: NA |
inherit.aes |
Default: TRUE |
A [ggplot2::Stat] representing the data transformations with required mappings for plotting conditional HDRs using [geom_hdr_boxplot].