Browse Source

initial commit

tags/v0.1.1
hrbrmstr 9 years ago
commit
809f51c49c
  1. 8
      .Rbuildignore
  2. 3
      .gitignore
  3. 5
      .travis.yml
  4. 25
      CONDUCT.md
  5. 11
      DESCRIPTION
  6. 2
      LICENSE
  7. 15
      NAMESPACE
  8. 145
      R/geom_bkde.r
  9. 209
      R/geom_xspline.r
  10. 10
      R/ggalt-package.r
  11. 132
      README.Rmd
  12. 162
      README.md
  13. BIN
      README_figs/README-unnamed-chunk-4-1.png
  14. BIN
      README_figs/README-unnamed-chunk-4-10.png
  15. BIN
      README_figs/README-unnamed-chunk-4-2.png
  16. BIN
      README_figs/README-unnamed-chunk-4-3.png
  17. BIN
      README_figs/README-unnamed-chunk-4-4.png
  18. BIN
      README_figs/README-unnamed-chunk-4-5.png
  19. BIN
      README_figs/README-unnamed-chunk-4-6.png
  20. BIN
      README_figs/README-unnamed-chunk-4-7.png
  21. BIN
      README_figs/README-unnamed-chunk-4-8.png
  22. BIN
      README_figs/README-unnamed-chunk-4-9.png
  23. 25
      ggalt.Rproj
  24. 114
      man/geom_bkde.Rd
  25. 174
      man/geom_xspline.Rd
  26. 14
      man/ggalt-ggproto.Rd
  27. 15
      man/ggalt.Rd
  28. 4
      tests/testthat.R
  29. 6
      tests/testthat/test-ggalt.R

8
.Rbuildignore

@ -0,0 +1,8 @@
^.*\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
^README-.*\.png$
^\.travis\.yml$
^CONDUCT\.md$
^README\.md$
^README_figs

3
.gitignore

@ -0,0 +1,3 @@
.Rproj.user
.Rhistory
.RData

5
.travis.yml

@ -0,0 +1,5 @@
# Sample .travis.yml for R projects
language: r
warnings_are_errors: true
sudo: required

25
CONDUCT.md

@ -0,0 +1,25 @@
# Contributor Code of Conduct
As contributors and maintainers of this project, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating documentation,
submitting pull requests or patches, and other activities.
We are committed to making participation in this project a harassment-free experience for
everyone, regardless of level of experience, gender, gender identity and expression,
sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
Examples of unacceptable behavior by participants include the use of sexual language or
imagery, derogatory comments or personal attacks, trolling, public or private harassment,
insults, or other unprofessional conduct.
Project maintainers have the right and responsibility to remove, edit, or reject comments,
commits, code, wiki edits, issues, and other contributions that are not aligned to this
Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
from the project team.
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
opening an issue or contacting one or more of the project maintainers.
This Code of Conduct is adapted from the Contributor Covenant
(http:contributor-covenant.org), version 1.0.0, available at
http://contributor-covenant.org/version/1/0/0/

11
DESCRIPTION

@ -0,0 +1,11 @@
Package: ggalt
Title: Extra Geoms, Stats and Coords for 'ggplot2'
Version: 0.0.1.9001
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)
License: AGPL + file LICENSE
LazyData: true
Suggests: testthat
Encoding: UTF-8
Imports: graphics, grDevices, dplyr, KernSmooth

2
LICENSE

@ -0,0 +1,2 @@
YEAR: 2015
COPYRIGHT HOLDER: Bob Rudis

15
NAMESPACE

@ -0,0 +1,15 @@
# Generated by roxygen2 (4.1.1): do not edit by hand
export(GeomBkde)
export(GeomXspline)
export(StatBkde)
export(StatXspline)
export(geom_bkde)
export(geom_xspline)
export(stat_bkde)
export(stat_xspline)
import(KernSmooth)
import(dplyr)
import(ggplot2)
import(grDevices)
import(graphics)

145
R/geom_bkde.r

@ -0,0 +1,145 @@
#' Display a smooth density estimate.
#'
#' A kernel density estimate, useful for display the distribution of variables
#' with underlying smoothness.
#'
#' @section Aesthetics:
#' \code{geom_bkde} understands the following aesthetics (required aesthetics
#' are in bold):
#' \itemize{
#' \item \strong{\code{x}}
#' \item \strong{\code{y}}
#' \item \code{alpha}
#' \item \code{color}
#' \item \code{fill}
#' \item \code{linetype}
#' \item \code{size}
#' }
#'
#' @param geom,stat Use to override the default connection between
#' \code{geom_bkde} and \code{stat_bkde}.
#' @seealso See \code{\link{geom_histogram}}, \code{\link{geom_freqpoly}} for
#' other methods of displaying continuous distribution.
#' See \code{\link{geom_violin}} for a compact density display.
#' @inheritParams ggplot2::geom_point
#' @export
geom_bkde <- function(mapping = NULL, data = NULL, stat = "bkde",
position = "identity", bandwidth, range.x=NULL, show.legend = NA, inherit.aes = TRUE,
...) {
layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomBkde,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(range.x=range.x,
...)
)
}
#' @rdname ggalt-ggproto
#' @format NULL
#' @usage NULL
#' @export
GeomBkde <- ggproto("GeomBkde", GeomArea,
default_aes = aes(colour = NA, fill = "grey20", size = 0.5, linetype = 1, alpha = NA)
)
#' @param bandwidth the kernel bandwidth smoothing parameter. see
#' \code{\link[KernSmooth]{bkde}} for details
#' @param kernel character string which determines the smoothing kernel. see
#' \code{\link[KernSmooth]{bkde}} for details
#' @param canonical logical flag: if TRUE, canonically scaled kernels are used.
#' see \code{\link[KernSmooth]{bkde}} for details
#' @param gridsize the number of equally spaced points at which to estimate the
#' density. see \code{\link[KernSmooth]{bkde}} for details
#' @param range.x vector containing the minimum and maximum values of x at which
#' to compute the estimate. see \code{\link[KernSmooth]{bkde}} for details
#' @param truncate logical flag: if TRUE, data with x values outside the range
#' specified by range.x are ignored. see \code{\link[KernSmooth]{bkde}}
#' for details
#' @section Computed variables:
#' \describe{
#' \item{density}{density estimate}
#' \item{count}{density * number of points - useful for stacked density
#' plots}
#' \item{scaled}{density estimate, scaled to maximum of 1}
#' }
#' @export
#' @rdname geom_bkde
#' @examples
#' data(geyser, package="MASS")
#'
#' ggplot(geyser, aes(x=duration)) +
#' stat_bkde(bandwidth=0.25)
#'
#' ggplot(geyser, aes(x=duration)) +
#' geom_bkde(bandwidth=0.25)
stat_bkde <- function(mapping = NULL, data = NULL, geom = "area",
position = "stack", kernel="normal", canonical=FALSE, bandwidth, gridsize=410,
range.x=NULL, truncate=TRUE, show.legend = NA, inherit.aes = TRUE, ...) {
layer(
data = data,
mapping = mapping,
stat = StatBkde,
geom = geom,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
kernel=kernel,
canonical=canonical,
bandwidth=bandwidth,
gridsize=gridsize,
range.x=range.x,
truncate=truncate,
...
)
)
}
#' @rdname ggalt-ggproto
#' @format NULL
#' @usage NULL
#' @export
StatBkde <- ggproto("StatBkde", Stat,
required_aes = "x",
default_aes = aes(y = ..density.., fill = NA),
compute_group = function(data, scales, kernel="normal", canonical=FALSE,
bandwidth, gridsize=410, range.x, truncate=TRUE) {
if (missing(range.x) | is.null(range.x)) range.x <- range(data$x)
compute_bkde(data$x, kernel=kernel, canonical=canonical,
bandwidth=bandwidth, gridsize=gridsize, range.x=range.x,
truncate=truncate)
}
)
compute_bkde <- function(x, kernel="normal", canonical=FALSE,
bandwidth, gridsize=410, range.x, truncate=TRUE) {
n <- length(x)
if (missing(range.x) | is.null(range.x)) range.x <- range(x)
dens <- KernSmooth::bkde(x, kernel, canonical, bandwidth, gridsize, range.x, truncate)
data.frame(
x = dens$x,
density = dens$y,
scaled = dens$y / max(dens$y, na.rm = TRUE),
count = dens$y * n,
n = n
)
}

209
R/geom_xspline.r

@ -0,0 +1,209 @@
#' Connect control points/observations with an X-spline
#'
#' Draw an X-spline, a curve drawn relative to control points/observations.
#' Patterned after \code{geom_line} in that it orders the points by \code{x}
#' first before computing the splines.
#'
#' @section Aesthetics:
#' \code{geom_xspline} understands the following aesthetics (required aesthetics
#' are in bold):
#' \itemize{
#' \item \strong{\code{x}}
#' \item \strong{\code{y}}
#' \item \code{alpha}
#' \item \code{color}
#' \item \code{linetype}
#' \item \code{size}
#' }
#'
#' @seealso
#' \code{\link[ggplot2]{geom_line}}: Connect observations (x order);
#' \code{\link[ggplot2]{geom_path}}: Connect observations;
#' \code{\link[ggplot2]{geom_polygon}}: Filled paths (polygons);
#' \code{\link[ggplot2]{geom_segment}}: Line segments;
#' \code{\link[graphics]{xspline}};
#' \code{\link[grid]{grid.xspline}}
#'
#' @details
#' An X-spline is a line drawn relative to control points. For each control
#' point, the line may pass through (interpolate) the control point or it may
#' only approach (approximate) the control point; the behaviour is determined
#' by a shape parameter for each control point.
#'
#' If the shape parameter is greater than zero, the spline approximates the
#' control points (and is very similar to a cubic B-spline when the shape is
#' 1). If the shape parameter is less than zero, the spline interpolates the
#' control points (and is very similar to a Catmull-Rom spline when the shape
#' is -1). If the shape parameter is 0, the spline forms a sharp corner at that
#' control point.
#'
#' For open X-splines, the start and end control points must have a shape of
#' 0 (and non-zero values are silently converted to zero).
#'
#' For open X-splines, by default the start and end control points are
#' replicated before the curve is drawn. A curve is drawn between (interpolating
#' or approximating) the second and third of each set of four control points,
#' so this default behaviour ensures that the resulting curve starts at the
#' first control point you have specified and ends at the last control point.
#' The default behaviour can be turned off via the repEnds argument.
#'
#' @inheritParams ggplot2::geom_line
#' @param geom,stat Use to override the default connection between
#' \code{geom_xspline} and \code{stat_xspline}.
#' @param spline_shape A numeric vector of values between -1 and 1, which
#' control the shape of the spline relative to the control points.
#' @param open A logical value indicating whether the spline is an open or a
#' closed shape.
#' @param rep_ends For open X-splines, a logical value indicating whether the
#' first and last control points should be replicated for drawing the
#' curve. Ignored for closed X-splines.
#' @references Blanc, C. and Schlick, C. (1995), "X-splines : A Spline Model
#' Designed for the End User", in \emph{Proceedings of SIGGRAPH 95},
#' pp. 377-386. \url{http://dept-info.labri.fr/~schlick/DOC/sig1.html}
#' @export
#' @examples
#' 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)))
#' )
#'
#' 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)
#'
#' 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(spline_shape=-0.4, 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(spline_shape=0.4, 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(spline_shape=1, 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(spline_shape=0, 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(spline_shape=-1, size=0.5)
geom_xspline <- function(mapping = NULL, data = NULL, stat = "xspline",
position = "identity", show.legend = NA,
inherit.aes = TRUE, na.rm = TRUE,
spline_shape=-0.25, open=TRUE, rep_ends=TRUE, ...) {
layer(
geom = GeomXspline,
mapping = mapping,
data = data,
stat = stat,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(spline_shape=spline_shape,
open=open,
rep_ends=rep_ends,
...)
)
}
#' GeomXspline
#' @rdname ggalt-ggproto
#' @format NULL
#' @usage NULL
#' @export
GeomXspline <- ggproto("GeomXspline", GeomLine,
required_aes = c("x", "y"),
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA)
)
#' @export
#' @rdname geom_xspline
#' @section Computed variables:
#' \itemize{
#' \item{x}
#' \item{y}
#' }
stat_xspline <- function(mapping = NULL, data = NULL, geom = "line",
position = "identity", show.legend = NA, inherit.aes = TRUE,
spline_shape=-0.25, open=TRUE, rep_ends=TRUE, ...) {
layer(
stat = StatXspline,
data = data,
mapping = mapping,
geom = geom,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(spline_shape=spline_shape,
open=open,
rep_ends=rep_ends,
...
)
)
}
#' @rdname ggalt-ggproto
#' @format NULL
#' @usage NULL
#' @export
StatXspline <- ggproto("StatXspline", Stat,
required_aes = c("x", "y"),
setup_params = function(data, params) {
params
},
compute_group = function(self, data, scales, params,
spline_shape=-0.25, open=TRUE, rep_ends=TRUE) {
tf <- tempfile(fileext=".png")
png(tf)
plot.new()
tmp <- xspline(data$x, data$y, spline_shape, open, rep_ends, draw=FALSE, NA, NA)
invisible(dev.off())
unlink(tf)
data.frame(x=tmp$x, y=tmp$y)
}
)
# function to do the xspline interpolation and return a data.frame since we have
# to do this graphics device wrapper
xspline_int <- function(dat, shape, open, rep_ends) {
# despite the "draw=FALSE" parameter, xspline still
# tries to use the graphics device so we have to
# do this to work around it
tf <- tempfile(fileext=".png")
png(tf)
plot.new()
tmp <- xspline(dat$x, dat$y, shape, open, rep_ends, draw=FALSE, NA, NA)
invisible(dev.off())
unlink(tf)
data.frame(x=tmp$x, y=tmp$y)
}

10
R/ggalt-package.r

@ -0,0 +1,10 @@
#' Extra Geoms, Stats and Coords for 'ggplot2'
#'
#' A package containing additional geoms, coords and stats for the revamped (late 2015) version
#' of ggplot2.
#'
#' @name ggalt
#' @docType package
#' @author Bob Rudis (@@hrbrmstr)
#' @import ggplot2 graphics grDevices dplyr KernSmooth
NULL

132
README.Rmd

@ -0,0 +1,132 @@
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.retina = 2,
fig.path = "README_figs/README-"
)
```
`ggalt` : Extra Geoms, Stats and Coords for `ggplot2`
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.
*NOTE*
Until the new `ggplot2` version is on CRAN, you'll need to install it from github (see below).
The following functions are implemented:
- `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`)
- `stat_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`)
### News
- Version 0.0.1.9000 released
### Installation
```{r eval=FALSE}
# you'll want to see the vignettes, trust me
devtools::install_github("hadley/ggplot2", build_vignettes=TRUE)
devtools::install_github("hrbrmstr/ggalt")
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```
### Usage
```{r}
library(ggalt)
# current verison
packageVersion("ggalt")
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)))
)
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)
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(spline_shape=-0.4, 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(spline_shape=0.4, 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(spline_shape=1, 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(spline_shape=0, 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(spline_shape=-1, size=0.5)
# Better density plots
data(geyser, package="MASS")
ggplot(geyser, aes(x=duration)) +
stat_bkde(bandwidth=0.25)
ggplot(geyser, aes(x=duration)) +
geom_bkde(bandwidth=0.25)
```
### 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).
By participating in this project you agree to abide by its terms.

162
README.md

@ -0,0 +1,162 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->
`ggalt` : Extra Geoms, Stats and Coords for `ggplot2`
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.
*NOTE*
Until the new `ggplot2` version is on CRAN, you'll need to install it from github (see below).
The following functions are implemented:
- `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`)
- `stat_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`)
### News
- Version 0.0.1.9000 released
### Installation
``` r
# you'll want to see the vignettes, trust me
devtools::install_github("hadley/ggplot2", build_vignettes=TRUE)
devtools::install_github("hrbrmstr/ggalt")
```
### Usage
``` r
library(ggalt)
#> Loading required package: ggplot2
# current verison
packageVersion("ggalt")
#> [1] '0.0.1.9001'
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)))
)
ggplot(dat, aes(x, y, group=group, color=group)) +
geom_point() +
geom_line()
```
<img src="README_figs/README-unnamed-chunk-4-1.png" title="" alt="" width="672" />
``` r
ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point() +
geom_line() +
geom_smooth(se=FALSE, linetype="dashed", size=0.5)
```
<img src="README_figs/README-unnamed-chunk-4-2.png" title="" alt="" width="672" />
``` r
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)
```
<img src="README_figs/README-unnamed-chunk-4-3.png" title="" alt="" width="672" />
``` r
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(spline_shape=-0.4, size=0.5)
```
<img src="README_figs/README-unnamed-chunk-4-4.png" title="" alt="" width="672" />
``` r
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(spline_shape=0.4, size=0.5)
```
<img src="README_figs/README-unnamed-chunk-4-5.png" title="" alt="" width="672" />
``` r
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(spline_shape=1, size=0.5)
```
<img src="README_figs/README-unnamed-chunk-4-6.png" title="" alt="" width="672" />
``` r
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(spline_shape=0, size=0.5)
```
<img src="README_figs/README-unnamed-chunk-4-7.png" title="" alt="" width="672" />
``` r
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(spline_shape=-1, size=0.5)
```
<img src="README_figs/README-unnamed-chunk-4-8.png" title="" alt="" width="672" />
``` r
# Better density plots
data(geyser, package="MASS")
ggplot(geyser, aes(x=duration)) +
stat_bkde(bandwidth=0.25)
```
<img src="README_figs/README-unnamed-chunk-4-9.png" title="" alt="" width="672" />
``` r
ggplot(geyser, aes(x=duration)) +
geom_bkde(bandwidth=0.25)
```
<img src="README_figs/README-unnamed-chunk-4-10.png" title="" alt="" width="672" />
### Test Results
``` r
library(ggalt)
library(testthat)
date()
#> [1] "Tue Sep 8 16:16:44 2015"
test_dir("tests/")
#> testthat results ========================================================================================================
#> OK: 0 SKIPPED: 0 FAILED: 0
#>
#> DONE
```
### Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

25
ggalt.Rproj

@ -0,0 +1,25 @@
Version: 1.0
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
Encoding: UTF-8
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
UseSpacesForTab: Yes
NumSpacesForTab: 2
RnwWeave: Sweave
LaTeX: pdfLaTeX
PackageBuildArgs: --resave-data
PackageCheckArgs: --as-cran

114
man/geom_bkde.Rd

@ -0,0 +1,114 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/geom_bkde.r
\name{geom_bkde}
\alias{geom_bkde}
\alias{stat_bkde}
\title{Display a smooth density estimate.}
\usage{
geom_bkde(mapping = NULL, data = NULL, stat = "bkde",
position = "identity", bandwidth, range.x = NULL, show.legend = NA,
inherit.aes = TRUE, ...)
stat_bkde(mapping = NULL, data = NULL, geom = "area",
position = "stack", kernel = "normal", canonical = FALSE, bandwidth,
gridsize = 410, range.x = NULL, truncate = TRUE, show.legend = NA,
inherit.aes = TRUE, ...)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
default), is combined with the default mapping at the top level of the
plot. You only need to supply \code{mapping} if there isn't a mapping
defined for the plot.}
\item{data}{A data frame. If specified, overrides the default data frame
defined at the top level of the plot.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
\item{bandwidth}{the kernel bandwidth smoothing parameter. see
\code{\link[KernSmooth]{bkde}} for details}
\item{range.x}{vector containing the minimum and maximum values of x at which
to compute the estimate. see \code{\link[KernSmooth]{bkde}} for details}
\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.}
\item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
\item{...}{other arguments passed on to \code{\link{layer}}. There are
three types of arguments you can use here:
\itemize{
\item Aesthetics: to set an aesthetic to a fixed value, like
\code{color = "red"} or \code{size = 3}.
\item Other arguments to the layer, for example you override the
default \code{stat} associated with the layer.
\item Other arguments passed on to the stat.
}}
\item{geom,stat}{Use to override the default connection between
\code{geom_bkde} and \code{stat_bkde}.}
\item{kernel}{character string which determines the smoothing kernel. see
\code{\link[KernSmooth]{bkde}} for details}
\item{canonical}{logical flag: if TRUE, canonically scaled kernels are used.
see \code{\link[KernSmooth]{bkde}} for details}
\item{gridsize}{the number of equally spaced points at which to estimate the
density. see \code{\link[KernSmooth]{bkde}} for details}
\item{truncate}{logical flag: if TRUE, data with x values outside the range
specified by range.x are ignored. see \code{\link[KernSmooth]{bkde}}
for details}
}
\description{
A kernel density estimate, useful for display the distribution of variables
with underlying smoothness.
}
\section{Aesthetics}{
\code{geom_bkde} understands the following aesthetics (required aesthetics
are in bold):
\itemize{
\item \strong{\code{x}}
\item \strong{\code{y}}
\item \code{alpha}
\item \code{color}
\item \code{fill}
\item \code{linetype}
\item \code{size}
}
}
\section{Computed variables}{
\describe{
\item{density}{density estimate}
\item{count}{density * number of points - useful for stacked density
plots}
\item{scaled}{density estimate, scaled to maximum of 1}
}
}
\examples{
data(geyser, package="MASS")
ggplot(geyser, aes(x=duration)) +
stat_bkde(bandwidth=0.25)
ggplot(geyser, aes(x=duration)) +
geom_bkde(bandwidth=0.25)
}
\seealso{
See \code{\link{geom_histogram}}, \code{\link{geom_freqpoly}} for
other methods of displaying continuous distribution.
See \code{\link{geom_violin}} for a compact density display.
}

174
man/geom_xspline.Rd

@ -0,0 +1,174 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/geom_xspline.r
\name{geom_xspline}
\alias{geom_xspline}
\alias{stat_xspline}
\title{Connect control points/observations with an X-spline}
\usage{
geom_xspline(mapping = NULL, data = NULL, stat = "xspline",
position = "identity", show.legend = NA, inherit.aes = TRUE,
na.rm = TRUE, spline_shape = -0.25, open = TRUE, rep_ends = TRUE, ...)
stat_xspline(mapping = NULL, data = NULL, geom = "line",
position = "identity", show.legend = NA, inherit.aes = TRUE,
spline_shape = -0.25, open = TRUE, rep_ends = TRUE, ...)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
default), is combined with the default mapping at the top level of the
plot. You only need to supply \code{mapping} if there isn't a mapping
defined for the plot.}
\item{data}{A data frame. If specified, overrides the default data frame
defined at the top level of the plot.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.}
\item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
\item{spline_shape}{A numeric vector of values between -1 and 1, which
control the shape of the spline relative to the control points.}
\item{open}{A logical value indicating whether the spline is an open or a
closed shape.}
\item{rep_ends}{For open X-splines, a logical value indicating whether the
first and last control points should be replicated for drawing the
curve. Ignored for closed X-splines.}
\item{...}{other arguments passed on to \code{\link{layer}}. There are
three types of arguments you can use here:
\itemize{
\item Aesthetics: to set an aesthetic to a fixed value, like
\code{color = "red"} or \code{size = 3}.
\item Other arguments to the layer, for example you override the
default \code{stat} associated with the layer.
\item Other arguments passed on to the stat.
}}
\item{geom,stat}{Use to override the default connection between
\code{geom_xspline} and \code{stat_xspline}.}
}
\description{
Draw an X-spline, a curve drawn relative to control points/observations.
Patterned after \code{geom_line} in that it orders the points by \code{x}
first before computing the splines.
}
\details{
An X-spline is a line drawn relative to control points. For each control
point, the line may pass through (interpolate) the control point or it may
only approach (approximate) the control point; the behaviour is determined
by a shape parameter for each control point.
If the shape parameter is greater than zero, the spline approximates the
control points (and is very similar to a cubic B-spline when the shape is
1). If the shape parameter is less than zero, the spline interpolates the
control points (and is very similar to a Catmull-Rom spline when the shape
is -1). If the shape parameter is 0, the spline forms a sharp corner at that
control point.
For open X-splines, the start and end control points must have a shape of
0 (and non-zero values are silently converted to zero).
For open X-splines, by default the start and end control points are
replicated before the curve is drawn. A curve is drawn between (interpolating
or approximating) the second and third of each set of four control points,
so this default behaviour ensures that the resulting curve starts at the
first control point you have specified and ends at the last control point.
The default behaviour can be turned off via the repEnds argument.
}
\section{Aesthetics}{
\code{geom_xspline} understands the following aesthetics (required aesthetics
are in bold):
\itemize{
\item \strong{\code{x}}
\item \strong{\code{y}}
\item \code{alpha}
\item \code{color}
\item \code{linetype}
\item \code{size}
}
}
\section{Computed variables}{
\itemize{
\item{x}
\item{y}
}
}
\examples{
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)))
)
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)
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(spline_shape=-0.4, 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(spline_shape=0.4, 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(spline_shape=1, 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(spline_shape=0, 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(spline_shape=-1, size=0.5)
}
\references{
Blanc, C. and Schlick, C. (1995), "X-splines : A Spline Model
Designed for the End User", in \emph{Proceedings of SIGGRAPH 95},
pp. 377-386. \url{http://dept-info.labri.fr/~schlick/DOC/sig1.html}
}
\seealso{
\code{\link[ggplot2]{geom_line}}: Connect observations (x order);
\code{\link[ggplot2]{geom_path}}: Connect observations;
\code{\link[ggplot2]{geom_polygon}}: Filled paths (polygons);
\code{\link[ggplot2]{geom_segment}}: Line segments;
\code{\link[graphics]{xspline}};
\code{\link[grid]{grid.xspline}}
}

14
man/ggalt-ggproto.Rd

@ -0,0 +1,14 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/geom_bkde.r, R/geom_xspline.r
\docType{data}
\name{GeomBkde}
\alias{GeomBkde}
\alias{GeomXspline}
\alias{StatBkde}
\alias{StatXspline}
\title{GeomXspline}
\description{
GeomXspline
}
\keyword{datasets}

15
man/ggalt.Rd

@ -0,0 +1,15 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/ggalt-package.r
\docType{package}
\name{ggalt}
\alias{ggalt}
\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.
}
\author{
Bob Rudis (@hrbrmstr)
}

4
tests/testthat.R

@ -0,0 +1,4 @@
library(testthat)
library(ggalt)
test_check("ggalt")

6
tests/testthat/test-ggalt.R

@ -0,0 +1,6 @@
context("basic functionality")
test_that("we can do something", {
#expect_that(some_function(), is_a("data.frame"))
})
Loading…
Cancel
Save