From 2c1a09e83b84a48d08d5fe1ae256bf8d41a303b8 Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Mon, 21 Dec 2015 13:18:10 -0500 Subject: [PATCH] pre-CRAN submission testing --- .Rbuildignore | 1 + DESCRIPTION | 9 +- NAMESPACE | 1 + R/coord_proj.r | 19 ++- R/geom_ash.r | 5 + R/geom_bkde.r | 2 + R/geom_bkde2d.r | 5 +- R/geom_xspline.r | 6 +- R/ggalt-package.r | 4 +- README.Rmd | 46 +++--- README.html | 284 ++++++++++++++++++++++++++++++++++++++ README.md | 129 +++++++++-------- README_figs/README-bkde2d-1.png | Bin 278538 -> 241757 bytes README_figs/README-bkde2d-2.png | Bin 278538 -> 114290 bytes README_figs/README-bkde_ash-8.png | Bin 89508 -> 87986 bytes man/coord_proj.Rd | 11 +- man/geom_bkde2d.Rd | 10 +- man/ggalt-ggproto.Rd | 19 ++- man/ggalt.Rd | 3 +- 19 files changed, 428 insertions(+), 126 deletions(-) create mode 100644 README.html diff --git a/.Rbuildignore b/.Rbuildignore index 2028405..4e689b2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ ^CONDUCT\.md$ ^README\.md$ ^README_figs +^README\.html$ diff --git a/DESCRIPTION b/DESCRIPTION index 17525ea..66b3476 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ggalt Title: Alternate/Extra 'Geoms', 'Stats' and 'Coords' for 'ggplot2' -Version: 0.0.4.9000 +Version: 0.1.0.9000 Authors@R: c(person("Bob", "Rudis", email = "bob@rudis.net", role = c("aut", "cre"))) Description: A package containing additional/alternate 'geoms', 'coords' and 'stats' for use with the revamped (late 2015) version of ggplot2. @@ -13,14 +13,17 @@ Suggests: testthat, gridExtra Encoding: UTF-8 +Enhances: ggplot2 Imports: graphics, grDevices, dplyr, + RColorBrewer, KernSmooth, proj4, scales, grid, gtable, - ash -RoxygenNote: 5.0.0 + ash, + MASS +RoxygenNote: 5.0.1 diff --git a/NAMESPACE b/NAMESPACE index 6ac0273..eedcc96 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -28,6 +28,7 @@ import(ggplot2) import(grDevices) import(graphics) import(proj4) +importFrom(RColorBrewer,brewer.pal) importFrom(grid,gList) importFrom(grid,gTree) importFrom(grid,grid.draw) diff --git a/R/coord_proj.r b/R/coord_proj.r index ffa89e0..23bb140 100644 --- a/R/coord_proj.r +++ b/R/coord_proj.r @@ -2,10 +2,11 @@ #' #' The representation of a portion of the earth, which is approximately #' spherical, onto a flat 2D plane requires a projection. This is what -#' \code{coord_proj} does, using the \link[proj4]{project()} function from +#' \code{coord_proj} does, using the \code{proj4::project()} function from #' the \code{proj4} package. #' -#' @param proj projection definition +#' @param proj projection definition. If left \code{NULL} will default to +#' a Robinson projection #' @param inverse if \code{TRUE} inverse projection is performed (from a #' cartographic projection into lat/long), otherwise projects from #' lat/long into a cartographic projection. @@ -20,10 +21,15 @@ #' @param xlim manually specific x limits (in degrees of longitude) #' @param ylim manually specific y limits (in degrees of latitude) #' @export -coord_proj <- function(proj="+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs", - inverse = FALSE, degrees = TRUE, +coord_proj <- function(proj=NULL, inverse = FALSE, degrees = TRUE, ellps.default="sphere", xlim = NULL, ylim = NULL) { + if (is.null(proj)) { + proj <- paste0(c("+proj=robin +lon_0=0 +x_0=0 +y_0=0", + "+ellps=WGS84 +datum=WGS84 +units=m +no_defs"), + collapse=" ") + } + ggproto(NULL, CoordProj, proj = proj, inverse = inverse, @@ -35,6 +41,11 @@ coord_proj <- function(proj="+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +da } +#' Geom Proto +#' @rdname ggalt-ggproto +#' @format NULL +#' @usage NULL +#' @keywords internal #' @export CoordProj <- ggproto("CoordProj", Coord, diff --git a/R/geom_ash.r b/R/geom_ash.r index 05b2495..3819353 100644 --- a/R/geom_ash.r +++ b/R/geom_ash.r @@ -79,6 +79,11 @@ stat_ash <- function(mapping = NULL, data = NULL, geom = "area", } +#' Geom Proto +#' @rdname ggalt-ggproto +#' @format NULL +#' @usage NULL +#' @keywords internal #' @export StatAsh <- ggproto("StatAsh", Stat, diff --git a/R/geom_bkde.r b/R/geom_bkde.r index 4a9d163..fc4edae 100644 --- a/R/geom_bkde.r +++ b/R/geom_bkde.r @@ -42,9 +42,11 @@ geom_bkde <- function(mapping = NULL, data = NULL, stat = "bkde", ) } +#' Geom Proto #' @rdname ggalt-ggproto #' @format NULL #' @usage NULL +#' @keywords internal #' @export GeomBkde <- ggproto("GeomBkde", GeomArea, default_aes = aes(colour = NA, fill = "gray20", size = 0.5, diff --git a/R/geom_bkde2d.r b/R/geom_bkde2d.r index dadc69a..e43978c 100644 --- a/R/geom_bkde2d.r +++ b/R/geom_bkde2d.r @@ -55,9 +55,11 @@ geom_bkde2d <- function(mapping = NULL, data = NULL, stat = "bkde2d", } +#' Geom Proto #' @rdname ggalt-ggproto #' @format NULL #' @usage NULL +#' @keywords internal #' @export GeomBkde2d <- ggproto("GeomBkde2d", GeomPath, default_aes = aes(colour = "#3366FF", size = 0.5, linetype = 1, alpha = NA) @@ -73,9 +75,10 @@ GeomBkde2d <- ggproto("GeomBkde2d", GeomPath, #' \code{\link[KernSmooth]{bkde2D}} for details. If \code{NULL}, #' it will be computed for you but will most likely not yield optimal #' results. see \code{\link[KernSmooth]{bkde2D}} for details -#' @param gridsize vector containing the number of equally spaced points in each +#' @param grid_size vector containing the number of equally spaced points in each #' direction over which the density is to be estimated. see #' \code{\link[KernSmooth]{bkde2D}} for details +#' @param geom default geom to use with this stat #' @param range.x a list containing two vectors, where each vector contains the #' minimum and maximum values of x at which to compute the estimate for #' each direction. see \code{\link[KernSmooth]{bkde2D}} for details diff --git a/R/geom_xspline.r b/R/geom_xspline.r index 6548800..7462aa0 100644 --- a/R/geom_xspline.r +++ b/R/geom_xspline.r @@ -127,17 +127,15 @@ geom_xspline <- function(mapping = NULL, data = NULL, stat = "xspline", ) } -#' GeomXspline +#' Geom Proto #' @rdname ggalt-ggproto #' @format NULL #' @usage NULL +#' @keywords internal #' @export GeomXspline <- ggproto("GeomXspline", GeomLine, - required_aes = c("x", "y"), - default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA) - ) #' @export diff --git a/R/ggalt-package.r b/R/ggalt-package.r index 25b6c93..9599ba0 100644 --- a/R/ggalt-package.r +++ b/R/ggalt-package.r @@ -1,7 +1,6 @@ #' Extra Geoms, Stats and Coords for 'ggplot2' #' -#' 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 ggplot2 2.0+ #' #' @name ggalt #' @docType package @@ -11,4 +10,5 @@ #' @importFrom grid grobName grobTree unit.c grobHeight grobWidth viewport #' grid.draw grobX grobY gTree gList #' @importFrom gtable gtable_col gtable_height gtable_width gtable_row gtable_col +#' @importFrom RColorBrewer brewer.pal NULL diff --git a/README.Rmd b/README.Rmd index b6584a4..e6cc7ed 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,5 +1,7 @@ --- output: + html_document: + keep_md: true md_document: variant: markdown_github --- @@ -17,17 +19,13 @@ fig.retina = 2, `ggalt` : Alternate/Extra 'Geoms', 'Stats' and 'Coords' for 'ggplot2' - A package containing additional/alternate 'geoms', 'coords' and 'stats' for use with the revamped (late 2015) version of ggplot2. + A package containing additional/alternate 'geoms', 'coords' and 'stats' for use with ggplot2 2.0+. 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 and an initial port of the (still needing work) `coord_proj`. -**NOTE** - -Until the new `ggplot2` version is on CRAN, you'll need to install it from github via `devtools::install_github("hrbrmstr/ggplot2")`. Locally, I have goth `ggalt` and my `ggplot2` in a "develment mode" install via `devtools::dev_mode()`. Since the new `ggplot2` breaks _many_ other packages (like `plotly`, CRAN `ggthemes`, `ggmap` and more), keeping it squirreled away in it's own area is a good idea until everyone catches up. - The following functions are implemented: -- `coord_proj` : Like `coord_map` only better `:-)` +- `coord_proj` : Like `coord_map` only better 😜 - `geom_xspline` : Connect control points/observations with an X-spline - `stat_xspline` : Connect control points/observations with an X-spline - `geom_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`) @@ -38,6 +36,7 @@ The following functions are implemented: ### News +- Version 0.1.0.9000 released - Tweaks for ggplot2 2.0 release - Version 0.0.4.9000 released - `stat_ash` - Version 0.0.3.9000 released - `coord_proj`! (requires my github copy of ggplot2 for now) - Version 0.0.2.9005 released - cleanup before blog post @@ -48,7 +47,7 @@ The following functions are implemented: ```{r eval=FALSE} # you'll want to see the vignettes, trust me -devtools::install_github("hadley/ggplot2", build_vignettes=TRUE) +install.packages("ggplot2") devtools::install_github("hrbrmstr/ggalt") ``` @@ -139,7 +138,7 @@ set.seed(1492) dat <- data.frame(cond = factor(rep(c("A","B"), each=200)), rating = c(rnorm(200),rnorm(200, mean=.8))) -ggplot(dat, aes(x=rating, color=cond)) + geom_bkde(alpha=0) +ggplot(dat, aes(x=rating, color=cond)) + geom_bkde(fill="#00000000") ggplot(dat, aes(x=rating, fill=cond)) + geom_bkde(alpha=0.3) @@ -154,9 +153,9 @@ grid.arrange(ggplot(dat, aes(x)) + stat_ash(), 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]) + + stat_ash(alpha=1/3, fill=cols[3]) + + stat_bkde(alpha=1/3, fill=cols[2]) + + stat_density(alpha=1/3, fill=cols[1]) + geom_rug() + labs(x=NULL, y="density/estimate") + scale_x_continuous(expand=c(0,0)) + @@ -168,15 +167,15 @@ ggplot(dat, aes(x)) + ### Alternate 2D density plots ```{r bkde2d} -geyser_dat <- data.frame(x=geyser$duration, y=geyser$waiting) +m <- ggplot(faithful, aes(x = eruptions, y = waiting)) + + geom_point() + + xlim(0.5, 6) + + ylim(40, 110) -ggplot(geyser_dat, aes(x, y)) + - geom_point() + - geom_bkde2d(bandwidth=c(0.7, 7)) +m + geom_bkde2d(bandwidth=c(0.5, 4)) + +m + stat_bkde2d(bandwidth=c(0.5, 4), aes(fill = ..level..), geom = "polygon") -ggplot(geyser_dat, aes(x, y)) + - geom_point() + - stat_bkde2d(bandwidth=c(0.7, 7)) ``` ### `coord_proj` LIVES! (still needs work) @@ -193,17 +192,6 @@ gg <- gg + coord_proj("+proj=wintri") gg ``` -### Test Results - -```{r} -library(ggalt) -library(testthat) - -date() - -test_dir("tests/") -``` - ### Code of Conduct Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). diff --git a/README.html b/README.html new file mode 100644 index 0000000..330ad74 --- /dev/null +++ b/README.html @@ -0,0 +1,284 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

ggalt : Alternate/Extra ‘Geoms’, ‘Stats’ and ‘Coords’ for ‘ggplot2’

+

A package containing additional/alternate ‘geoms’, ‘coords’ and ‘stats’ for use with ggplot2 2.0+.

+

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 and an initial port of the (still needing work) coord_proj.

+

The following functions are implemented:

+ +
+

News

+
    +
  • Version 0.1.0.9000 released - Tweaks for ggplot2 2.0 release
  • +
  • Version 0.0.4.9000 released - stat_ash
  • +
  • Version 0.0.3.9000 released - coord_proj! (requires my github copy of ggplot2 for now)
  • +
  • Version 0.0.2.9005 released - cleanup before blog post
  • +
  • Version 0.0.2.9002 released - working 2D density plots
  • +
  • Version 0.0.2.9000 released
  • +
+
+
+

Installation

+
# you'll want to see the vignettes, trust me
+install.packages("ggplot2")
+devtools::install_github("hrbrmstr/ggalt")
+
+
+

Usage

+
library(ggplot2)
+library(gridExtra)
+library(ggalt)
+
+# current verison
+packageVersion("ggalt")
+#> [1] '0.1.0.9000'
+
+set.seed(1492)
+dat <- data.frame(x=c(1:10, 1:10, 1:10),
+                  y=c(sample(15:30, 10), 2*sample(15:30, 10), 3*sample(15:30, 10)),
+                  group=factor(c(rep(1, 10), rep(2, 10), rep(3, 10)))
+)
+
+
+

Splines!

+
ggplot(dat, aes(x, y, group=group, color=group)) +
+  geom_point() +
+  geom_line()
+

+

+ggplot(dat, aes(x, y, group=group, color=factor(group))) +
+  geom_point() +
+  geom_line() +
+  geom_smooth(se=FALSE, linetype="dashed", size=0.5)
+

+

+ggplot(dat, aes(x, y, group=group, color=factor(group))) +
+  geom_point(color="black") +
+  geom_smooth(se=FALSE, linetype="dashed", size=0.5) +
+  geom_xspline(size=0.5)
+