From 3f7a565f3fdb47ccb2a3d0357f273096ddb8ebf9 Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Tue, 5 Dec 2017 16:15:08 -0500 Subject: [PATCH] shld pass CRAN checks on Travis now --- NAMESPACE | 2 ++ R/geom-statebins.r | 59 +++++++++++++++++++++++++++++---------- R/statebins-package.R | 4 +-- R/theme-statebin.R | 33 ++++++++++------------ man/geom_statebins.Rd | 72 ++++++++++++++++++++++++++++++++++++++---------- man/statebins-package.Rd | 4 +-- man/theme_statebins.Rd | 5 ++-- 7 files changed, 125 insertions(+), 54 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 59cc8b1..26a6c8a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(GeomStatebins) export(geom_statebins) export(statebins) export(theme_statebins) +importFrom(ggplot2,"%+replace%") importFrom(ggplot2,Geom) importFrom(ggplot2,GeomRect) importFrom(ggplot2,Stat) @@ -25,6 +26,7 @@ importFrom(ggplot2,ggtitle) importFrom(ggplot2,guides) importFrom(ggplot2,labs) importFrom(ggplot2,layer) +importFrom(ggplot2,margin) importFrom(ggplot2,rel) importFrom(ggplot2,resolution) importFrom(ggplot2,scale_color_manual) diff --git a/R/geom-statebins.r b/R/geom-statebins.r index ebdd281..7d79a9d 100644 --- a/R/geom-statebins.r +++ b/R/geom-statebins.r @@ -1,22 +1,53 @@ -#' A statebins Geom (WIP!) -#' -#' WIP!!!!!!!!!!! Full geom documentation coming soon. See Details and the Examples for now. -#' -#' For now, you pass in: -#' -#' - `border_col` (border color of the state squares, default "`white`") -#' - `border_size` (thickness of the square state borders) -#' - `lbl_size` (the relative font size of the state label text, default `3`) -#' - `dark_lbl` (the color for the state label text when it shld be dark text on light background) -#' - `light_lbl` (the color for the state label text when it shld be light text on dark background) -#' - `radius` (corner radius --- `0` for a "square") -#' -#' You also need to (ok, _should_) pass in two `aes()` mappings: +#' A statebins Geom #' +#' Pass in a data frame of states and values and let this do the work. It enables +#' easy faceting and makes it simpler to have a uniform legend across all the +#' plots.\cr +#' \cr +#' There are two special/critical `aes()` mappings:\cr +#' \cr #' - `state` (so the geom knows which column to map the state names/abbrevs to) #' - `fill` (which column you're mapping the filling for the squares with) #' #' @md +#' @param mapping Set of aesthetic mappings created by `aes()` or +#' `aes_()`. If specified and `inherit.aes = TRUE` (the +#' default), it is combined with the default mapping at the top level of the +#' plot. You must supply `mapping` if there is no plot mapping. +#' @param data The data to be displayed in this layer. There are three +#' options: +#' +#' If `NULL`, the default, the data is inherited from the plot +#' data as specified in the call to `ggplot()`. +#' +#' A `data.frame`, or other object, will override the plot +#' data. All objects will be fortified to produce a data frame. See +#' `fortify()` for which variables will be created. +#' +#' A `function` will be called with a single argument, +#' the plot data. The return value must be a `data.frame.`, and +#' will be used as the layer data. +#' @param border_col border color of the state squares, default "`white`" +#' @param border_size thickness of the square state borders +#' @param lbl_size font size (relative) of the label text +#' @param dark_lbl,light_lbl colrs to be uses when the label should be dark or light. +#' The function automagically computes when this should be. +#' @param radius the corner radius +#' @param na.rm If `FALSE`, the default, missing values are removed with +#' a warning. If `TRUE`, missing values are silently removed. +#' @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. +#' @param show.legend logical. Should this layer be included in the legends? +#' `NA`, the default, includes if any aesthetics are mapped. +#' `FALSE` never includes, and `TRUE` always includes. +#' It can also be a named logical vector to finely select the aesthetics to +#' display. +#' @param inherit.aes If `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. `borders()`. #' @export #' @examples \dontrun{ #' library(statebins) diff --git a/R/statebins-package.R b/R/statebins-package.R index 878d04f..8a2708c 100644 --- a/R/statebins-package.R +++ b/R/statebins-package.R @@ -1,4 +1,4 @@ -#' statebins is an alternative to choropleth maps for US States +#' statebins is an alternative to choropleth maps for U.S. States #' #' @md #' @name statebins-package @@ -10,6 +10,6 @@ #' @importFrom ggplot2 geom_point geom_text scale_color_manual guides theme labs #' @importFrom ggplot2 scale_x_continuous scale_y_continuous coord_equal theme_bw #' @importFrom ggplot2 aes element_rect element_blank element_text resolution -#' @importFrom ggplot2 aes_string aes_ scale_y_reverse layer GeomRect +#' @importFrom ggplot2 aes_string aes_ scale_y_reverse layer GeomRect margin %+replace% #' @importFrom ggplot2 scale_fill_brewer ggtitle rel ggproto draw_key_polygon Geom Stat NULL diff --git a/R/theme-statebin.R b/R/theme-statebin.R index 5a30334..2edbc79 100644 --- a/R/theme-statebin.R +++ b/R/theme-statebin.R @@ -4,29 +4,26 @@ #' #' @md #' @param legend_position fills in `legend.position` -#' @param base_family,base_size,base_line_size,base_rect_size same as `theme_bw()` +#' @param base_family,base_size same as `theme_bw()` #' @export theme_statebins <- function(legend_position="bottom", - base_size = 11, base_family = "", - base_line_size = base_size/22, - base_rect_size = base_size/22) { + base_size = 11, + base_family = "") { - if ("base_line_size" %in% names(formals(ggplot2::theme_bw))) { - gg <- theme_bw(base_family = base_family, base_size = base_size, - base_line_size = base_line_size, base_rect_size = base_rect_size) - } else { - gg <- theme_bw(base_family = base_family, base_size = base_size) - gg <- gg + theme(size = base_line_size) - gg <- gg + theme(rect = element_rect(fill = "white", colour = "black", - size = base_rect_size, linetype = 1)) - } + gg <- theme_bw(base_size = base_size, base_family = base_family) %+replace% + theme(axis.line = element_blank(), + axis.text = element_blank(), + axis.ticks = element_blank(), + axis.title = element_blank(), + panel.background = element_blank(), + panel.border = element_blank(), + panel.grid = element_blank(), + panel.spacing = unit(0, "lines"), + plot.background = element_blank(), + legend.justification = c(0, 0), + legend.position = legend_position) - gg <- gg + theme(panel.border=element_blank()) gg <- gg + theme(strip.background = element_rect(color="#2b2b2b", fill="white")) - gg <- gg + theme(panel.grid=element_blank()) - gg <- gg + theme(panel.background=element_blank()) - gg <- gg + theme(axis.ticks=element_blank()) - gg <- gg + theme(axis.text=element_blank()) gg <- gg + theme(plot.title=element_text(hjust=0.5)) gg <- gg + theme(axis.title.x=element_text(hjust=0.5)) gg <- gg + theme(legend.position=legend_position) diff --git a/man/geom_statebins.Rd b/man/geom_statebins.Rd index 64fb367..4d77dd0 100644 --- a/man/geom_statebins.Rd +++ b/man/geom_statebins.Rd @@ -4,7 +4,7 @@ \name{geom_statebins} \alias{geom_statebins} \alias{GeomStatebins} -\title{A statebins Geom (WIP!)} +\title{A statebins Geom} \format{An object of class \code{GeomStatebins} (inherits from \code{Geom}, \code{ggproto}, \code{gg}) of length 7.} \usage{ geom_statebins(mapping = NULL, data = NULL, border_col = "white", @@ -14,21 +14,63 @@ geom_statebins(mapping = NULL, data = NULL, border_col = "white", GeomStatebins } -\description{ -WIP!!!!!!!!!!! Full geom documentation coming soon. See Details and the Examples for now. -} -\details{ -For now, you pass in: -\itemize{ -\item \code{border_col} (border color of the state squares, default "\code{white}") -\item \code{border_size} (thickness of the square state borders) -\item \code{lbl_size} (the relative font size of the state label text, default \code{3}) -\item \code{dark_lbl} (the color for the state label text when it shld be dark text on light background) -\item \code{light_lbl} (the color for the state label text when it shld be light text on dark background) -\item \code{radius} (corner radius --- \code{0} for a "square") -} +\arguments{ +\item{mapping}{Set of aesthetic mappings created by \code{aes()} or +\code{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{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{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{border_col}{border color of the state squares, default "\code{white}"} -You also need to (ok, \emph{should}) pass in two \code{aes()} mappings: +\item{border_size}{thickness of the square state borders} + +\item{lbl_size}{font size (relative) of the label text} + +\item{dark_lbl, light_lbl}{colrs to be uses when the label should be dark or light. +The function automagically computes when this should be.} + +\item{radius}{the corner radius} + +\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, missing values are removed with +a warning. If \code{TRUE}, missing values are silently removed.} + +\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. +It can also be a named logical vector to finely select the aesthetics to +display.} + +\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{borders()}.} +} +\description{ +Pass in a data frame of states and values and let this do the work. It enables +easy faceting and makes it simpler to have a uniform legend across all the +plots.\cr +\cr +There are two special/critical \code{aes()} mappings:\cr +\cr \itemize{ \item \code{state} (so the geom knows which column to map the state names/abbrevs to) \item \code{fill} (which column you're mapping the filling for the squares with) diff --git a/man/statebins-package.Rd b/man/statebins-package.Rd index 6a4bba4..f858e66 100644 --- a/man/statebins-package.Rd +++ b/man/statebins-package.Rd @@ -3,9 +3,9 @@ \docType{package} \name{statebins-package} \alias{statebins-package} -\title{statebins is an alternative to choropleth maps for US States} +\title{statebins is an alternative to choropleth maps for U.S. States} \description{ -statebins is an alternative to choropleth maps for US States +statebins is an alternative to choropleth maps for U.S. States } \author{ Bob Rudis (bob@rud.is) diff --git a/man/theme_statebins.Rd b/man/theme_statebins.Rd index be3b73b..3c06b2f 100644 --- a/man/theme_statebins.Rd +++ b/man/theme_statebins.Rd @@ -5,13 +5,12 @@ \title{Base statebins theme} \usage{ theme_statebins(legend_position = "bottom", base_size = 11, - base_family = "", base_line_size = base_size/22, - base_rect_size = base_size/22) + base_family = "") } \arguments{ \item{legend_position}{fills in \code{legend.position}} -\item{base_family, base_size, base_line_size, base_rect_size}{same as \code{theme_bw()}} +\item{base_family, base_size}{same as \code{theme_bw()}} } \description{ Clears out most of the cruft. Builds off of \code{theme_bw()}