Package gghdr
imports the package
hdrcde
and provides tools for
plotting highest density regions in the ggplot2 framework.
- central box bounded by Q1 and Q3 representing the interquartile range
- whiskers extending from Q1 - 1.5(Q3 - Q1) to Q3 + to 1.5(Q3 - Q1), representing 99% coverage for large samples
- median represented by a horizontal line
#> This is hdrcde 3.3
#> Warning: package 'ggplot2' was built under R version 3.5.2
There are different ways to summarize a distribution but the highest density region allows the display of multimodality.
- Region bounded by the interquartile range is replaced by 50% HDR
- Region bounded by the whiskers is replaced by the 99% HDR
- The mode is represented by a horizontal line
library(hdrcde)
hdr.boxplot(faithful$eruptions)
library(ggplot2)
faithful %>% ggplot(aes(y = )) + geom_hdr_boxplot()
- a density plot
- the endpoints of each interval in each HDR on the x-axis
- a straight line showing value of the density at the boundaries of each HDR
hdr.den(faithful$eruptions)
#> $hdr
#> [,1] [,2] [,3] [,4]
#> 99% 1.323392 2.819361 3.152823 5.282328
#> 95% 1.500534 2.520984 3.500000 5.091921
#> 50% 1.923841 2.025015 3.940445 4.773299
#>
#> $mode
#> [1] 4.379365
#>
#> $falpha
#> 1% 5% 50%
#> 0.06791362 0.15330569 0.36003920
#ggplot(faithful, aes(x=eruptions)) + geom_density()
- geom_density() - to represent the density
- geom_hdr_rug() - The endpoints of each interval in each HDR on the x-axis
- geom_hline() - The value of the density at the boundaries of each HDR
gghdr() = geom_density() + geom_hdr_rug() + geom_hline()
library(ggplot2)
faithful %>% ggplot(aes(y = , x = )) + geom_hdr()