Browse Source

geom_ubar

pull/38/head
boB Rudis 7 years ago
parent
commit
b8ac117e57
No known key found for this signature in database GPG Key ID: 2A514A4997464560
  1. 3
      DESCRIPTION
  2. 2
      NAMESPACE
  3. 4
      NEWS.md
  4. 80
      R/geom_ubar.r
  5. 1
      README.Rmd
  6. 3
      README.md
  7. BIN
      README_figs/README-dumbbell2-1.png
  8. BIN
      README_figs/README-horizon-1.png
  9. 84
      man/geom_ubar.Rd
  10. 4
      man/ggalt-ggproto.Rd

3
DESCRIPTION

@ -1,7 +1,7 @@
Package: ggalt
Title: Extra Coordinate Systems, 'Geoms', Statistical Transformations, Scales
and Fonts for 'ggplot2'
Version: 0.4.0
Version: 0.5.0
Maintainer: Bob Rudis <bob@rud.is>
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre")),
@ -73,6 +73,7 @@ Collate:
'geom_twoway_bar.r'
'geom_xspline.r'
'geom_xspline2.r'
'geom_ubar.r'
'stat-stepribbon.r'
'ggalt-package.r'
'grob_absolute.r'

2
NAMESPACE

@ -16,6 +16,7 @@ export(GeomEncircle)
export(GeomHorizon)
export(GeomLollipop)
export(GeomStateface)
export(GeomUbar)
export(GeomXSpline2)
export(GeomXspline)
export(Kb)
@ -38,6 +39,7 @@ export(geom_encircle)
export(geom_horizon)
export(geom_lollipop)
export(geom_stateface)
export(geom_ubar)
export(geom_xspline)
export(load_stateface)
export(show_stateface)

4
NEWS.md

@ -1,3 +1,7 @@
0.5.0
=====================
* `geom_ubar()` : unform bar charts based on `geom_segment()`
0.4.0
=====================
* Fixed `coord_proj()`

80
R/geom_ubar.r

@ -0,0 +1,80 @@
#' Uniform "bar" charts
#'
#' I've been using `geom_segment` more to make "bar" charts, setting
#' `xend` to whatever `x` is and `yend` to `0`. The bar widths remain
#' constant without any tricks and you have granular control over the
#' segment width. I decided it was time to make a `geom`.
#'
#' Dumbbell dot plots — dot plots with two or more series of data — are an
#' alternative to the clustered bar chart or slope graph.
#'
#' @md
#' @section Aesthetics:
#' `geom_ubar`` understands the following aesthetics (required aesthetics are in bold):
#'
#' - **`x`**
#' - **`y`**
#' - `alpha`
#' - `colour`
#' - `group`
#' - `linetype`
#' - `size`
#'
#' @inheritParams ggplot2::layer
#' @param na.rm If `FALSE` (the default), removes missing values with
#' a warning. If `TRUE` silently removes missing values.
#' @param ... other arguments passed on to `layer`. These are
#' often aesthetics, used to set an aesthetic to a fixed value, like
#' `color = "red"` or `size = 3`. They may also be parameters
#' to the paired geom/stat.
#' @inheritParams ggplot2::layer
#' @export
#' @examples
#' library(ggplot2)
#'
#' data(economics)
#' ggplot(economics, aes(date, uempmed)) +
#' geom_ubar()
geom_ubar <- function(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ...,
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
stat = "identity",
geom = GeomUbar,
position = "identity",
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
na.rm = na.rm,
...
)
)
}
#' @rdname ggalt-ggproto
#' @format NULL
#' @usage NULL
#' @export
GeomUbar <- ggproto("GeomUbar", Geom,
required_aes = c("x", "y"),
non_missing_aes = c("size"),
default_aes = aes(
size = 0.25, colour = "black", alpha = NA
),
setup_data = function(data, params) {
transform(data, xend = x, yend = 0)
},
draw_group = function(data, panel_scales, coord) {
ggplot2::GeomSegment$draw_panel(data, panel_scales, coord)
}
)

1
README.Rmd

@ -19,6 +19,7 @@ A compendium of 'geoms', 'coords', 'stats', scales and fonts for 'ggplot2', incl
The following functions are implemented:
- `geom_ubar` : Uniform width bar charts
- `geom_horizon` : Horizon charts (modified from <https://github.com/AtherEnergy/ggTimeSeries>)
- `coord_proj` : Like `coord_map`, only better (prbly shld use this with `geom_cartogram` as `geom_map`'s new defaults are ugh)
- `geom_xspline` : Connect control points/observations with an X-spline

3
README.md

@ -8,6 +8,7 @@ A compendium of 'geoms', 'coords', 'stats', scales and fonts for 'ggplot2', incl
The following functions are implemented:
- `geom_ubar` : Uniform width bar charts
- `geom_horizon` : Horizon charts (modified from <https://github.com/AtherEnergy/ggTimeSeries>)
- `coord_proj` : Like `coord_map`, only better (prbly shld use this with `geom_cartogram` as `geom_map`'s new defaults are ugh)
- `geom_xspline` : Connect control points/observations with an X-spline
@ -42,7 +43,7 @@ library(ggalt)
# current verison
packageVersion("ggalt")
## [1] '0.4.0'
## [1] '0.5.0'
set.seed(1492)
dat <- data.frame(x=c(1:10, 1:10, 1:10),

BIN
README_figs/README-dumbbell2-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

BIN
README_figs/README-horizon-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 791 KiB

After

Width:  |  Height:  |  Size: 791 KiB

84
man/geom_ubar.Rd

@ -0,0 +1,84 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/geom_ubar.r
\name{geom_ubar}
\alias{geom_ubar}
\title{Uniform "bar" charts}
\usage{
geom_ubar(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ..., na.rm = FALSE, 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), it is combined with the default mapping at the top level of the
plot. You must supply \code{mapping} if there is no plot mapping.}
\item{data}{The data to be displayed in this layer. There are three
options:
If \code{NULL}, the default, the data is inherited from the plot
data as specified in the call to \code{\link{ggplot}}.
A \code{data.frame}, or other object, will override the plot
data. All objects will be fortified to produce a data frame. See
\code{\link{fortify}} for which variables will be created.
A \code{function} will be called with a single argument,
the plot data. The return value must be a \code{data.frame.}, and
will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
\item{...}{other arguments passed on to \code{layer}. These are
often aesthetics, used to set an aesthetic to a fixed value, like
\code{color = "red"} or \code{size = 3}. They may also be parameters
to the paired geom/stat.}
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
\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}}.}
}
\description{
I've been using \code{geom_segment} more to make "bar" charts, setting
\code{xend} to whatever \code{x} is and \code{yend} to \code{0}. The bar widths remain
constant without any tricks and you have granular control over the
segment width. I decided it was time to make a \code{geom}.
}
\details{
Dumbbell dot plots — dot plots with two or more series of data — are an
alternative to the clustered bar chart or slope graph.
}
\section{Aesthetics}{
`geom_ubar`` understands the following aesthetics (required aesthetics are in bold):
\itemize{
\item \strong{\code{x}}
\item \strong{\code{y}}
\item \code{alpha}
\item \code{colour}
\item \code{group}
\item \code{linetype}
\item \code{size}
}
}
\examples{
library(ggplot2)
data(economics)
ggplot(economics, aes(date, uempmed)) +
geom_ubar()
}

4
man/ggalt-ggproto.Rd

@ -1,7 +1,8 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/coord_proj.r, R/geom_ash.r, R/geom_bkde.r,
% R/geom_bkde2d.r, R/geom_dumbbell.R, R/geom_encircle.r, R/geom_lollipop.r,
% R/geom_xspline.r, R/geom_xspline2.r, R/stat-stepribbon.r, R/stateface.r
% R/geom_xspline.r, R/geom_xspline2.r, R/geom_ubar.r, R/stat-stepribbon.r,
% R/stateface.r
\docType{data}
\name{CoordProj}
\alias{CoordProj}
@ -16,6 +17,7 @@
\alias{GeomXspline}
\alias{StatXspline}
\alias{GeomXSpline2}
\alias{GeomUbar}
\alias{StatStepribbon}
\alias{GeomStateface}
\title{Geom Proto}

Loading…
Cancel
Save