diff --git a/DESCRIPTION b/DESCRIPTION index 98f6df3..0305f5d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ggalt Title: Extra Geoms, Stats and Coords for 'ggplot2' -Version: 0.0.2.9000 +Version: 0.0.2.9002 Authors@R: c(person("Bob", "Rudis", email = "bob@rudis.net", role = c("aut", "cre"))) Description: A package contains additional geoms, coords and stats for the revamped (late 2015) version of ggplot2. Depends: R (>= 3.0.0), ggplot2 (>= 1.0.1.9003) diff --git a/R/geom_bkde2d.r b/R/geom_bkde2d.r index 082c53e..e745d8c 100644 --- a/R/geom_bkde2d.r +++ b/R/geom_bkde2d.r @@ -81,7 +81,15 @@ StatBkde2d <- ggproto("StatBkde2d", Stat, compute_group = function(data, scales, contour=TRUE, bandwidth, grid_size=c(51, 51), range.x=NULL, truncate=TRUE) { - if (is.null(range.x)) range.x <- list(range(data$x), range(data$y)) + if (is.null(range.x)) { + x_range <- range(data$x) + y_range <- range(data$y) + x_range[1] <- x_range[1] - 1.5 * bandwidth[1] + x_range[2] <- x_range[2] + 1.5 * bandwidth[1] + y_range[1] <- y_range[1] - 1.5 * bandwidth[2] + y_range[2] <- y_range[2] + 1.5 * bandwidth[2] + range.x <- list(x_range, y_range) + } dens <- KernSmooth::bkde2D( as.matrix(data.frame(x=data$x, y=data$y)), diff --git a/README.Rmd b/README.Rmd index fbda585..da906db 100644 --- a/README.Rmd +++ b/README.Rmd @@ -20,9 +20,7 @@ knitr::opts_chunk$set( A package containing additional geoms, coords and stats for the revamped (late 2015) version of ggplot2. -The first two forays into this brave, new `ggplot2` world are _splines_! and being able to -use the (much better) `KernSmooth::bkde` for density plots. Support for `KernSmooth::bkde2D` is -a WIP. +The first three forays into this brave, new `ggplot2` world are _splines_! and being able to use the (much better) `KernSmooth::bkde` and `KernSmooth::bkde2D` for density plots. *NOTE* @@ -34,11 +32,12 @@ The following functions are implemented: - `stat_xspline` : Connect control points/observations with an X-spline - `geom_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`) - `stat_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`) -- `geom_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`) **WIP** -- `stat_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`) **WIP** +- `geom_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`) +- `stat_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`) ### News +- Version 0.0.2.9002 released - working 2D density plots - Version 0.0.2.9000 released ### Installation @@ -122,14 +121,11 @@ geyser_dat <- data.frame(x=geyser$duration, y=geyser$waiting) ggplot(geyser_dat, aes(x, y)) + geom_point() + - geom_bkde2d(bandwidth=c(0.7, 7)) + - xlim(0, 6) + ylim(35, 120) + geom_bkde2d(bandwidth=c(0.7, 7)) ggplot(geyser_dat, aes(x, y)) + geom_point() + - stat_bkde2d(bandwidth=c(0.7, 7)) + - xlim(0, 6) + ylim(35, 120) - + stat_bkde2d(bandwidth=c(0.7, 7)) ``` ### Test Results diff --git a/README.md b/README.md index ace1425..2905942 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A package containing additional geoms, coords and stats for the revamped (late 2015) version of ggplot2. -The first two forays into this brave, new `ggplot2` world are *splines*! and being able to use the (much better) `KernSmooth::bkde` for density plots. Support for `KernSmooth::bkde2D` is a WIP. +The first three forays into this brave, new `ggplot2` world are *splines*! and being able to use the (much better) `KernSmooth::bkde` and `KernSmooth::bkde2D` for density plots. *NOTE* @@ -15,11 +15,12 @@ The following functions are implemented: - `stat_xspline` : Connect control points/observations with an X-spline - `geom_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`) - `stat_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`) -- `geom_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`) **WIP** -- `stat_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`) **WIP** +- `geom_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`) +- `stat_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`) ### News +- Version 0.0.2.9002 released - working 2D density plots - Version 0.0.2.9000 released ### Installation @@ -38,7 +39,7 @@ library(ggalt) # current verison packageVersion("ggalt") -#> [1] '0.0.2.9000' +#> [1] '0.0.2.9002' set.seed(1492) dat <- data.frame(x=c(1:10, 1:10, 1:10), @@ -151,8 +152,7 @@ geyser_dat <- data.frame(x=geyser$duration, y=geyser$waiting) ggplot(geyser_dat, aes(x, y)) + geom_point() + - geom_bkde2d(bandwidth=c(0.7, 7)) + - xlim(0, 6) + ylim(35, 120) + geom_bkde2d(bandwidth=c(0.7, 7)) ``` @@ -161,8 +161,7 @@ ggplot(geyser_dat, aes(x, y)) + ggplot(geyser_dat, aes(x, y)) + geom_point() + - stat_bkde2d(bandwidth=c(0.7, 7)) + - xlim(0, 6) + ylim(35, 120) + stat_bkde2d(bandwidth=c(0.7, 7)) ``` @@ -174,7 +173,7 @@ library(ggalt) library(testthat) date() -#> [1] "Tue Sep 8 18:56:26 2015" +#> [1] "Tue Sep 8 21:13:04 2015" test_dir("tests/") #> testthat results ======================================================================================================== diff --git a/README_figs/README-unnamed-chunk-4-11.png b/README_figs/README-unnamed-chunk-4-11.png index 3b2b4df..6b14a99 100644 Binary files a/README_figs/README-unnamed-chunk-4-11.png and b/README_figs/README-unnamed-chunk-4-11.png differ diff --git a/README_figs/README-unnamed-chunk-4-12.png b/README_figs/README-unnamed-chunk-4-12.png index 3b2b4df..6b14a99 100644 Binary files a/README_figs/README-unnamed-chunk-4-12.png and b/README_figs/README-unnamed-chunk-4-12.png differ