Browse Source

testing dev_mode(); added example to ash

tags/v0.1.1
hrbrmstr 9 years ago
parent
commit
6bf9899be3
  1. 2
      DESCRIPTION
  2. 27
      R/geom_ash.r
  3. 2
      README.md
  4. BIN
      README_figs/README-unnamed-chunk-4-18.png
  5. 4
      man/ggalt.Rd
  6. 24
      man/stat_ash.Rd

2
DESCRIPTION

@ -7,6 +7,6 @@ Description: A package containing additional/alternate 'geoms', 'coords' and 'st
Depends: R (>= 3.0.0), ggplot2 (>= 1.0.1.9003)
License: AGPL + file LICENSE
LazyData: true
Suggests: testthat
Suggests: testthat, gridExtra
Encoding: UTF-8
Imports: graphics, grDevices, dplyr, KernSmooth, proj4, scales, grid, gtable, ash

27
R/geom_ash.r

@ -30,9 +30,30 @@
#' }
#' @section Computed variables:
#' \describe{
#' \item{\code{estimate}}{ash estimates}
#' \item{\code{density}}{ash density estimate}
#' }
#' @export
#' @examples
#' # compare
#' library(gridExtra)
#' set.seed(1492)
#' dat <- data.frame(x=rnorm(100))
#' grid.arrange(ggplot(dat, aes(x)) + stat_ash(),
#' ggplot(dat, aes(x)) + stat_bkde(),
#' ggplot(dat, aes(x)) + stat_density(),
#' nrow=3)
#'
#' cols <- RColorBrewer::brewer.pal(3, "Dark2")
#' ggplot(dat, aes(x)) +
#' stat_ash(alpha=1/2, fill=cols[3]) +
#' stat_bkde(alpha=1/2, fill=cols[2]) +
#' stat_density(alpha=1/2, fill=cols[1]) +
#' geom_rug() +
#' labs(x=NULL, y="density/estimate") +
#' scale_x_continuous(expand=c(0,0)) +
#' theme_bw() +
#' theme(panel.grid=element_blank()) +
#' theme(panel.border=element_blank())
stat_ash <- function(mapping = NULL, data = NULL, geom = "area",
position = "stack",
ab = NULL, nbin = 50, m = 5, kopt = c(2, 2),
@ -62,7 +83,7 @@ StatAsh <- ggproto("StatAsh", Stat,
required_aes = c("x"),
default_aes = aes(y = ..estimate.., colour = NA, fill = "gray20", size = 0.5,
default_aes = aes(y = ..density.., colour = NA, fill = "gray20", size = 0.5,
linetype = 1, alpha = NA),
@ -83,7 +104,7 @@ StatAsh <- ggproto("StatAsh", Stat,
if (ash_res$ier == 1) message("Estimate nonzero outside interval ab.")
data.frame(x=ash_res$x, estimate=ash_res$y)
data.frame(x=ash_res$x, density=ash_res$y)
}

2
README.md

@ -271,7 +271,7 @@ library(ggalt)
library(testthat)
date()
#> [1] "Sat Sep 12 13:12:29 2015"
#> [1] "Sun Sep 13 07:22:24 2015"
test_dir("tests/")
#> testthat results ========================================================================================================

BIN
README_figs/README-unnamed-chunk-4-18.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

4
man/ggalt.Rd

@ -6,8 +6,8 @@
\alias{ggalt-package}
\title{Extra Geoms, Stats and Coords for 'ggplot2'}
\description{
A package containing additional geoms, coords and stats for the revamped (late 2015) version
of ggplot2.
A package containing additional geoms, coords and stats for the revamped
(late 2015) version of ggplot2.
}
\author{
Bob Rudis (@hrbrmstr)

24
man/stat_ash.Rd

@ -75,9 +75,31 @@ are in bold):
\section{Computed variables}{
\describe{
\item{\code{estimate}}{ash estimates}
\item{\code{density}}{ash density estimate}
}
}
\examples{
# compare
library(gridExtra)
set.seed(1492)
dat <- data.frame(x=rnorm(100))
grid.arrange(ggplot(dat, aes(x)) + stat_ash(),
ggplot(dat, aes(x)) + stat_bkde(),
ggplot(dat, aes(x)) + stat_density(),
nrow=3)
cols <- RColorBrewer::brewer.pal(3, "Dark2")
ggplot(dat, aes(x)) +
stat_ash(alpha=1/2, fill=cols[3]) +
stat_bkde(alpha=1/2, fill=cols[2]) +
stat_density(alpha=1/2, fill=cols[1]) +
geom_rug() +
labs(x=NULL, y="density/estimate") +
scale_x_continuous(expand=c(0,0)) +
theme_bw() +
theme(panel.grid=element_blank()) +
theme(panel.border=element_blank())
}
\references{
David Scott (1992), \emph{"Multivariate Density Estimation,"}
John Wiley, (chapter 5 in particular).\cr

Loading…
Cancel
Save