Compare commits
No commits in common. 'master' and 'gh-pages' have entirely different histories.
@ -1,19 +0,0 @@ |
|||
^.*\.Rproj$ |
|||
^\.Rproj\.user$ |
|||
^.*md$ |
|||
^\.travis\.yml$ |
|||
^.*README_files$ |
|||
^.*README_files/$ |
|||
^.*README_files/.*$ |
|||
^README\.html$ |
|||
^tmp$ |
|||
^tmp/$ |
|||
^tmp/.*$ |
|||
^cran-comments\.md$ |
|||
^README.gfm-ascii_identifiers_files$ |
|||
^README.gfm-ascii_identifiers_files/$ |
|||
^README.gfm-ascii_identifiers_files/.*$ |
|||
^appveyor\.yml$ |
|||
^codecov\.yml$ |
|||
^data-raw$ |
|||
^\.github$ |
@ -1,3 +0,0 @@ |
|||
# These are supported funding model platforms |
|||
|
|||
patreon: hrbrmstr |
@ -1,7 +0,0 @@ |
|||
.Rproj.user |
|||
.Rhistory |
|||
.RData |
|||
.Rproj |
|||
src/*.o |
|||
src/*.so |
|||
src/*.dll |
@ -1,6 +0,0 @@ |
|||
language: R |
|||
sudo: false |
|||
cache: packages |
|||
|
|||
after_success: |
|||
- Rscript -e 'covr::codecov()' |
@ -1,56 +0,0 @@ |
|||
Package: statebins |
|||
Type: Package |
|||
Title: Create United States Uniform Cartogram Heatmaps |
|||
Version: 1.4.0 |
|||
Date: 2020-07-08 |
|||
Authors@R: c( |
|||
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), |
|||
comment = c(ORCID = "0000-0001-5670-2640")), |
|||
person("Harold", "Gil", email = "hgil@marionhealth.org", role = "ctb", |
|||
comment = "fix for show.guide"), |
|||
person("Brian", "Adams", email = "btadams478@gmail.com", role = "ctb", |
|||
comment = "theme testing & feedback"), |
|||
person("Thomas", "Wood", role = "ctb", |
|||
comment = "Significant suggestions & testing that made new features possible"), |
|||
person("Mathew", "Kiang", role = "ctb", |
|||
comment = "Minor fix for NA handling") |
|||
) |
|||
Maintainer: Bob Rudis <bob@rud.is> |
|||
Description: The cartogram heatmaps generated by the included methods |
|||
are an alternative to choropleth maps for the United States |
|||
and are based on work by the Washington Post graphics department in their report |
|||
on "The states most threatened by trade" |
|||
(<http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/>). |
|||
"State bins" preserve as much of the geographic placement of the states as |
|||
possible but have the look and feel of a traditional heatmap. Functions are |
|||
provided that allow for use of a binned, discrete scale, a continuous scale |
|||
or manually specified colors depending on what is needed for the underlying data. |
|||
URL: https://gitlab.com/hrbrmstr/statebins |
|||
BugReports: https://gitlab.com/hrbrmstr/statebins/issues |
|||
License: MIT + file LICENSE |
|||
Encoding: UTF-8 |
|||
Suggests: |
|||
testthat, |
|||
viridis, |
|||
RColorBrewer, |
|||
covr |
|||
Depends: |
|||
R (>= 3.5.0), |
|||
Imports: |
|||
ggplot2 (>= 2.2.1), |
|||
scales (>= 0.5.0), |
|||
grid |
|||
RoxygenNote: 7.1.0 |
|||
Collate: |
|||
'aaa.R' |
|||
'geom-oscar.R' |
|||
'geom-otile.R' |
|||
'oscar-grob.R' |
|||
'geom-rrect.r' |
|||
'geom-rtile.R' |
|||
'geom-statebins.r' |
|||
'gutil.R' |
|||
'statebins-package.R' |
|||
'statebins.R' |
|||
'theme-statebin.R' |
|||
'util.R' |
@ -1,2 +0,0 @@ |
|||
YEAR: 2015 |
|||
COPYRIGHT HOLDER: Bob Rudis |
@ -1,41 +0,0 @@ |
|||
# Generated by roxygen2: do not edit by hand |
|||
|
|||
export(GeomStatebins) |
|||
export(geom_statebins) |
|||
export(statebins) |
|||
export(theme_statebins) |
|||
importFrom(ggplot2,"%+replace%") |
|||
importFrom(ggplot2,Geom) |
|||
importFrom(ggplot2,GeomRect) |
|||
importFrom(ggplot2,Stat) |
|||
importFrom(ggplot2,aes) |
|||
importFrom(ggplot2,aes_) |
|||
importFrom(ggplot2,aes_string) |
|||
importFrom(ggplot2,coord_equal) |
|||
importFrom(ggplot2,draw_key_polygon) |
|||
importFrom(ggplot2,element_blank) |
|||
importFrom(ggplot2,element_rect) |
|||
importFrom(ggplot2,element_text) |
|||
importFrom(ggplot2,geom_point) |
|||
importFrom(ggplot2,geom_text) |
|||
importFrom(ggplot2,geom_tile) |
|||
importFrom(ggplot2,ggplot) |
|||
importFrom(ggplot2,ggplotGrob) |
|||
importFrom(ggplot2,ggproto) |
|||
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) |
|||
importFrom(ggplot2,scale_fill_brewer) |
|||
importFrom(ggplot2,scale_fill_manual) |
|||
importFrom(ggplot2,scale_x_continuous) |
|||
importFrom(ggplot2,scale_y_continuous) |
|||
importFrom(ggplot2,scale_y_reverse) |
|||
importFrom(ggplot2,theme) |
|||
importFrom(ggplot2,theme_bw) |
|||
importFrom(grid,unit) |
|||
importFrom(scales,alpha) |
@ -1,28 +0,0 @@ |
|||
# statebins 1.4.0 |
|||
* New `state_tbl` dataset to make it easier to complete partial state data data frames |
|||
|
|||
# statebins 1.3.0 |
|||
* Added support for `VI`/`Virgin Islands` |
|||
* Supports auto-computation of when to use light & dark label colors |
|||
* New `theme_statebins()` |
|||
* New `geom_statebins()` |
|||
* Rounded rectangle support (with user-defined corner radius)! |
|||
* Completely re-designed the interface and will not be providing backwards-compatibility. |
|||
|
|||
# statebins 1.2.2 |
|||
* CRAN update |
|||
|
|||
# statebins 1.2.1 |
|||
* Added support for `PR`/`Puerto Rico`[[1](https://github.com/hrbrmstr/statebins/issues/2)] |
|||
and fixed a bug (#3) when using anything but a `data.frame` as input. Also no longer fails |
|||
(deals with the following but with a warning) when duplicate states are in the input data |
|||
or invalid states are in the input data. |
|||
|
|||
# statebins 1.1.0 |
|||
* `statebins_manual()` for manual placement of colors and moving of AK in support of a |
|||
(PR #1 by @hansthompson) |
|||
|
|||
# statebins 1.0.0 |
|||
* initial release |
|||
|
|||
|
@ -1,40 +0,0 @@ |
|||
state_coords <- structure(list(abbrev = c("AL", "AK", "AZ", "AR", "CA", "CO", |
|||
"CT", "DC", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", |
|||
"KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", |
|||
"NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", |
|||
"RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY", |
|||
"PR", "VI", "NYC"), |
|||
state = c("Alabama", "Alaska", "Arizona", "Arkansas", |
|||
"California", "Colorado", "Connecticut", "District of Columbia", |
|||
"Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", |
|||
"Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", |
|||
"Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", |
|||
"Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", |
|||
"New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", |
|||
"Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", |
|||
"South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", |
|||
"Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming", |
|||
"Puerto Rico", "Virgin Islands", "New York City"), |
|||
col = c(8L, 1L, 3L, 6L, 2L, 4L, 11L, 10L, 11L, 10L, |
|||
9L, 1L, 3L, 7L, 7L, 6L, 5L, 7L, 6L, 12L, 10L, 11L, 8L, 6L, 7L, |
|||
6L, 4L, 5L, 3L, 12L, 10L, 4L, 10L, 8L, 5L, 8L, 5L, 2L, 9L, 12L, |
|||
9L, 5L, 7L, 5L, 3L, 11L, 9L, 2L, 8L, 7L, 4L, 12L, 12L, 12), |
|||
row = c(7L, 7L, |
|||
6L, 6L, 5L, 5L, 4L, 6L, 5L, 8L, 7L, 8L, 3L, 3L, 4L, 4L, 6L, 5L, |
|||
7L, 1L, 5L, 3L, 3L, 3L, 7L, 5L, 3L, 5L, 4L, 2L, 4L, 6L, 3L, 6L, |
|||
3L, 4L, 7L, 4L, 4L, 4L, 6L, 4L, 6L, 8L, 5L, 2L, 5L, 3L, 5L, 2L, 4L, |
|||
8L, 7L, 3L)), |
|||
.Names = c("abbrev", "state", "col", "row"), |
|||
class = "data.frame", row.names = c(NA, -54L)) |
|||
|
|||
state_coords <- state_coords[order(state_coords$state),] |
|||
|
|||
b_state_coords <- state_coords |
|||
colnames(b_state_coords) <- c("abbrev", "state", "x", "y") |
|||
b_state_coords$y <- -b_state_coords$y |
|||
|
|||
#' "State" abbreviation to name data frame |
|||
#' |
|||
#' @name state_tbl |
|||
#' @docType data |
|||
NULL |
@ -1,99 +0,0 @@ |
|||
# |
|||
# geom_oscar <- function(mapping = NULL, data = NULL, |
|||
# ..., |
|||
# na.rm = FALSE, |
|||
# show.legend = NA, |
|||
# inherit.aes = TRUE) { |
|||
# |
|||
# stat = "oscar" |
|||
# position = "identity" |
|||
# |
|||
# layer( |
|||
# data = data, |
|||
# mapping = mapping, |
|||
# stat = stat, |
|||
# geom = GeomOscar, |
|||
# position = position, |
|||
# show.legend = show.legend, |
|||
# inherit.aes = inherit.aes, |
|||
# params = list( |
|||
# na.rm = na.rm, |
|||
# ... |
|||
# ) |
|||
# ) |
|||
# } |
|||
# |
|||
# StatOscar<- ggplot2::ggproto("StatOscar", Stat, |
|||
# |
|||
# required_aes = c("xmin", "xmax", "ymin", "ymax"), |
|||
# |
|||
# default_aes = ggplot2::aes( |
|||
# l_fill = "blue", r_fill = "red", colour = NA, size = 0.1, linetype = 1, alpha = NA |
|||
# ), |
|||
# |
|||
# required_aes = c("x", "y"), |
|||
# |
|||
# compute_panel = function(data, scales) { |
|||
# data |
|||
# } |
|||
# |
|||
# ) |
|||
# |
|||
# stat_oscar <- function(mapping = NULL, data = NULL, geom = "oscar", |
|||
# position = "identity", na.rm = FALSE, n = 500, revolutions = NULL, |
|||
# show.legend = NA, inherit.aes = TRUE, ...) { |
|||
# |
|||
# layer( |
|||
# stat = StatOscar, data = data, mapping = mapping, geom = geom, |
|||
# position = position, show.legend = show.legend, inherit.aes = inherit.aes, |
|||
# params = list(na.rm = na.rm, ...) |
|||
# ) |
|||
# |
|||
# } |
|||
# |
|||
# GeomOscar <- ggplot2::ggproto("GeomOscar", ggplot2::Geom, |
|||
# |
|||
# default_aes = ggplot2::aes( |
|||
# l_fill = "blue", r_fill = "red", colour = NA, size = 0.1, linetype = 1, alpha = NA |
|||
# ), |
|||
# |
|||
# draw_panel = function(self, data, panel_params, coord) { |
|||
# |
|||
# coords <- coord$transform(data, panel_params) |
|||
# |
|||
# lapply(1:length(coords$xmin), function(i) { |
|||
# |
|||
# oscarGrob( |
|||
# name = as.character(i), |
|||
# coords$xmin[i], coords$ymax[i], |
|||
# width = (coords$xmax[i] - coords$xmin[i]), |
|||
# height = (coords$ymax[i] - coords$ymin)[i], |
|||
# default.units = "native", |
|||
# gpbl = grid::gpar( |
|||
# col = coords$colour[i], |
|||
# fill = alpha(coords$l_fill[i], coords$alpha[i]), |
|||
# lwd = coords$size[i] * .pt, |
|||
# lty = coords$linetype[i], |
|||
# lineend = "butt" |
|||
# ), |
|||
# gptr = grid::gpar( |
|||
# col = coords$colour[i], |
|||
# fill = alpha(coords$r_fill[i], coords$alpha[i]), |
|||
# lwd = coords$size[i] * .pt, |
|||
# lty = coords$linetype[i], |
|||
# lineend = "butt" |
|||
# ) |
|||
# |
|||
# ) |
|||
# |
|||
# }) -> gl |
|||
# |
|||
# grobs <- do.call(grid::gList, gl) |
|||
# |
|||
# ggname("geom_oscar", grid::grobTree(children = grobs)) |
|||
# |
|||
# }, |
|||
# |
|||
# draw_key = ggplot2::draw_key_polygon |
|||
# |
|||
# ) |
@ -1,69 +0,0 @@ |
|||
# geom_otile <- function(mapping = NULL, data = NULL, ..., |
|||
# na.rm = FALSE, |
|||
# show.legend = NA, |
|||
# inherit.aes = TRUE) { |
|||
# |
|||
# stat <- "otile" |
|||
# position <- "identity" |
|||
# |
|||
# ggplot2::layer( |
|||
# data = data, |
|||
# mapping = mapping, |
|||
# stat = stat, |
|||
# geom = GeomOtile, |
|||
# position = position, |
|||
# show.legend = show.legend, |
|||
# inherit.aes = inherit.aes, |
|||
# params = list( |
|||
# na.rm = na.rm, |
|||
# ... |
|||
# ) |
|||
# ) |
|||
# } |
|||
# |
|||
# StatOtile <- ggplot2::ggproto("StatOtile", Stat, |
|||
# |
|||
# default_aes = ggplot2::aes( |
|||
# colour = NA, size = 0.1, linetype = 1, alpha = NA, l_fill="blue", r_fill="red" |
|||
# ), |
|||
# |
|||
# required_aes = c("x", "y"), |
|||
# |
|||
# compute_panel = function(data, scales) { |
|||
# data |
|||
# } |
|||
# |
|||
# ) |
|||
# |
|||
# stat_otile <- function(mapping = NULL, data = NULL, geom = "otile", |
|||
# position = "identity", na.rm = FALSE, |
|||
# show.legend = NA, inherit.aes = TRUE, ...) { |
|||
# |
|||
# layer( |
|||
# stat = StatOtile, data = data, mapping = mapping, geom = geom, |
|||
# position = position, show.legend = show.legend, inherit.aes = inherit.aes, |
|||
# params = list(na.rm = na.rm, ...) |
|||
# ) |
|||
# |
|||
# } |
|||
# |
|||
# GeomOtile <- ggplot2::ggproto("GeomOtile", GeomOscar, |
|||
# |
|||
# default_aes = ggplot2::aes( |
|||
# l_fill = "blue", r_fill = "red", colour = NA, size = 0.1, linetype = 1, alpha = NA |
|||
# ), |
|||
# |
|||
# setup_data = function(data, params) { |
|||
# data$width <- data$width %||% params$width %||% ggplot2::resolution(data$x, FALSE) |
|||
# data$height <- data$height %||% params$height %||% ggplot2::resolution(data$y, FALSE) |
|||
# |
|||
# transform(data, |
|||
# xmin = x - width / 2, xmax = x + width / 2, width = NULL, |
|||
# ymin = y - height / 2, ymax = y + height / 2, height = NULL |
|||
# ) |
|||
# }, |
|||
# |
|||
# draw_key = ggplot2::draw_key_polygon |
|||
# |
|||
# ) |
|||
# |
@ -1,65 +0,0 @@ |
|||
geom_rrect <- function(mapping = NULL, data = NULL, |
|||
stat = "identity", position = "identity", |
|||
radius = grid::unit(6, "pt"), |
|||
..., |
|||
na.rm = FALSE, |
|||
show.legend = NA, |
|||
inherit.aes = TRUE) { |
|||
layer( |
|||
data = data, |
|||
mapping = mapping, |
|||
stat = stat, |
|||
geom = GeomRrect, |
|||
position = position, |
|||
show.legend = show.legend, |
|||
inherit.aes = inherit.aes, |
|||
params = list( |
|||
radius = radius, |
|||
na.rm = na.rm, |
|||
... |
|||
) |
|||
) |
|||
} |
|||
|
|||
GeomRrect <- ggplot2::ggproto("GeomRrect", ggplot2::Geom, |
|||
|
|||
default_aes = ggplot2::aes( |
|||
colour = NA, fill = "grey35", size = 0.5, linetype = 1, alpha = NA |
|||
), |
|||
|
|||
required_aes = c("xmin", "xmax", "ymin", "ymax"), |
|||
|
|||
draw_panel = function(self, data, panel_params, coord, |
|||
radius = grid::unit(6, "pt")) { |
|||
|
|||
coords <- coord$transform(data, panel_params) |
|||
|
|||
lapply(1:length(coords$xmin), function(i) { |
|||
|
|||
grid::roundrectGrob( |
|||
coords$xmin[i], coords$ymax[i], |
|||
width = (coords$xmax[i] - coords$xmin[i]), |
|||
height = (coords$ymax[i] - coords$ymin)[i], |
|||
r = radius, |
|||
default.units = "native", |
|||
just = c("left", "top"), |
|||
gp = grid::gpar( |
|||
col = coords$colour[i], |
|||
fill = alpha(coords$fill[i], coords$alpha[i]), |
|||
lwd = coords$size[i] * .pt, |
|||
lty = coords$linetype[i], |
|||
lineend = "butt" |
|||
) |
|||
) |
|||
|
|||
}) -> gl |
|||
|
|||
grobs <- do.call(grid::gList, gl) |
|||
|
|||
ggname("geom_rrect", grid::grobTree(children = grobs)) |
|||
|
|||
}, |
|||
|
|||
draw_key = ggplot2::draw_key_polygon |
|||
|
|||
) |
@ -1,46 +0,0 @@ |
|||
geom_rtile <- function(mapping = NULL, data = NULL, |
|||
stat = "identity", position = "identity", |
|||
radius = grid::unit(6, "pt"), |
|||
..., |
|||
na.rm = FALSE, |
|||
show.legend = NA, |
|||
inherit.aes = TRUE) { |
|||
ggplot2::layer( |
|||
data = data, |
|||
mapping = mapping, |
|||
stat = stat, |
|||
geom = GeomRtile, |
|||
position = position, |
|||
show.legend = show.legend, |
|||
inherit.aes = inherit.aes, |
|||
params = list( |
|||
radius = radius, |
|||
na.rm = na.rm, |
|||
... |
|||
) |
|||
) |
|||
} |
|||
|
|||
GeomRtile <- ggplot2::ggproto("GeomRtile", GeomRrect, |
|||
|
|||
extra_params = c("na.rm", "width", "height"), |
|||
|
|||
setup_data = function(data, params) { |
|||
data$width <- data$width %||% params$width %||% ggplot2::resolution(data$x, FALSE) |
|||
data$height <- data$height %||% params$height %||% ggplot2::resolution(data$y, FALSE) |
|||
|
|||
transform(data, |
|||
xmin = x - width / 2, xmax = x + width / 2, width = NULL, |
|||
ymin = y - height / 2, ymax = y + height / 2, height = NULL |
|||
) |
|||
}, |
|||
|
|||
default_aes = ggplot2::aes( |
|||
fill = "grey20", colour = NA, size = 0.1, linetype = 1, alpha = NA |
|||
), |
|||
|
|||
required_aes = c("x", "y"), |
|||
|
|||
draw_key = ggplot2::draw_key_polygon |
|||
|
|||
) |
@ -1,175 +0,0 @@ |
|||
#' 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) |
|||
#' library(cdcfluview) |
|||
#' library(hrbrthemes) |
|||
#' library(tidyverse) |
|||
#' |
|||
#' flu <- ili_weekly_activity_indicators(2017) |
|||
#' |
|||
#' ggplot(flu, aes(state=statename, fill=activity_level)) + |
|||
#' geom_statebins() + |
|||
#' coord_equal() + |
|||
#' viridis::scale_fill_viridis( |
|||
#' name = "ILI Activity Level ", limits=c(0,10), breaks=0:10, option = "magma", direction = -1 |
|||
#' ) + |
|||
#' facet_wrap(~weekend) + |
|||
#' labs(title="2017-18 Flu Season ILI Activity Level") + |
|||
#' theme_statebins(base_family = font_ps) + |
|||
#' theme(plot.title=element_text(size=16, hjust=0)) + |
|||
#' theme(plot.margin = margin(30,30,30,30)) |
|||
#' } |
|||
geom_statebins <- function( |
|||
mapping = NULL, data = NULL, |
|||
border_col = "white", border_size = 2, |
|||
lbl_size = 3, dark_lbl = "black", light_lbl = "white", |
|||
radius = grid::unit(6, "pt"), |
|||
..., |
|||
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { |
|||
|
|||
ggplot2::layer( |
|||
data = data, |
|||
mapping = mapping, |
|||
stat = "identity", |
|||
geom = GeomStatebins, |
|||
position = "identity", |
|||
show.legend = show.legend, |
|||
inherit.aes = inherit.aes, |
|||
params = list( |
|||
border_col = border_col, |
|||
border_size = border_size, |
|||
lbl_size = lbl_size, |
|||
dark_lbl = dark_lbl, |
|||
light_lbl = light_lbl, |
|||
radius = radius, |
|||
na.rm = na.rm, |
|||
... |
|||
) |
|||
) |
|||
} |
|||
|
|||
#' @rdname geom_statebins |
|||
#' @export |
|||
GeomStatebins <- ggplot2::ggproto("GeomStatebins", ggplot2::Geom, |
|||
|
|||
default_aes = ggplot2::aes( |
|||
fill = "grey20", colour = NA, size = 0.1, linetype = 1, |
|||
state = "state", label="abbrev", angle = 0, hjust = 0.5, |
|||
vjust = 0.5, alpha = NA, family = "", fontface = 1, lineheight = 1.2 |
|||
), |
|||
|
|||
extra_params = c("na.rm", "width", "height"), |
|||
|
|||
setup_data = function(data, params) { |
|||
|
|||
# message("setup_data()") |
|||
# saveRDS(data, "/tmp/data.rds") |
|||
|
|||
state_data <- data.frame(data, stringsAsFactors=FALSE) |
|||
|
|||
if (max(nchar(state_data[,"state"])) <= 3) { |
|||
merge.x <- "abbrev" |
|||
} else { |
|||
merge.x <- "state" |
|||
} |
|||
|
|||
state_data <- validate_states(state_data, "state", merge.x, ignore_dups=TRUE) |
|||
|
|||
st.dat <- merge(b_state_coords, state_data, |
|||
by.x=merge.x, by.y="state", all.y=TRUE, sort=TRUE) |
|||
|
|||
st.dat$width <- st.dat$width %||% params$width %||% ggplot2::resolution(st.dat$x, FALSE) |
|||
st.dat$height <- st.dat$height %||% params$height %||% ggplot2::resolution(st.dat$y, FALSE) |
|||
|
|||
transform(st.dat, |
|||
xmin = x - width / 2, xmax = x + width / 2, width = NULL, |
|||
ymin = y - height / 2, ymax = y + height / 2, height = NULL |
|||
) -> xdat |
|||
|
|||
# saveRDS(xdat, "/tmp/setupdata.rds") |
|||
|
|||
xdat |
|||
|
|||
}, |
|||
|
|||
required_aes = c("state", "fill"), |
|||
|
|||
draw_panel = function(self, data, panel_params, coord, |
|||
border_col = "white", border_size = 2, |
|||
lbl_size = 3, dark_lbl = "black", light_lbl = "white", |
|||
radius = grid::unit(6, "pt")) { |
|||
|
|||
tile_data <- data |
|||
tile_data$colour <- border_col |
|||
tile_data$size <- border_size |
|||
|
|||
text_data <- data |
|||
text_data$label <- data$abbrev |
|||
text_data$fill <- NA |
|||
text_data$size <- lbl_size |
|||
text_data$colour <- .sb_invert(data$fill, dark_lbl, light_lbl) |
|||
|
|||
coord <- coord_equal() |
|||
|
|||
grid::gList( |
|||
GeomRtile$draw_panel(tile_data, panel_params, coord, radius), |
|||
ggplot2::GeomText$draw_panel(text_data, panel_params, coord) |
|||
) -> grobs |
|||
|
|||
ggname("geom_statebins", grid::grobTree(children = grobs)) |
|||
|
|||
}, |
|||
|
|||
draw_key = ggplot2::draw_key_polygon |
|||
|
|||
) |
@ -1,8 +0,0 @@ |
|||
# Name ggplot grid object |
|||
# Convenience function to name grid objects |
|||
# |
|||
# @keyword internal |
|||
ggname <- function(prefix, grob) { |
|||
grob$name <- grid::grobName(grob, prefix) |
|||
grob |
|||
} |
@ -1,48 +0,0 @@ |
|||
# |
|||
# oscarGrob <- function(x=unit(0.5, "npc"), y=unit(0.5, "npc"), |
|||
# width=unit(1, "npc"), height=unit(1, "npc"), |
|||
# default.units="npc", |
|||
# name=NULL, gpbl=gpar(), gptr=gpar(), vp=NULL) { |
|||
# if (!is.unit(x)) |
|||
# x <- unit(x, default.units) |
|||
# if (!is.unit(y)) |
|||
# y <- unit(y, default.units) |
|||
# if (!is.unit(width)) |
|||
# width <- unit(width, default.units) |
|||
# if (!is.unit(height)) |
|||
# height <- unit(height, default.units) |
|||
# |
|||
# if (length(name) == 0) name <- "oscar" |
|||
# |
|||
# ggname( |
|||
# |
|||
# name, |
|||
# |
|||
# grid::grobTree( |
|||
# |
|||
# grob(x=unit.c(x, x+width, x, x), |
|||
# y=unit.c(y, y, y+height, y), |
|||
# name=sprintf("%s_bl", name), gp=gpbl, vp=vp, cl="polygon"), |
|||
# |
|||
# grob(x=unit.c(x+width, x, x+width, x+width), |
|||
# y=unit.c(y+height, y+height, y, y+height), |
|||
# name=sprintf("%s_tr", name), gp=gptr, vp=vp, cl="polygon") |
|||
# ) |
|||
# |
|||
# ) |
|||
# |
|||
# } |
|||
# |
|||
# grid.oscar <- function(x=unit(0.5, "npc"), y=unit(0.5, "npc"), |
|||
# width=unit(1, "npc"), height=unit(1, "npc"), |
|||
# default.units="npc", |
|||
# name=NULL, gpbl=gpar(), gptr=gpar(), |
|||
# draw=TRUE, vp=NULL) { |
|||
# |
|||
# rg <- oscarGrob(x=x, y=y, width=width, height=height, |
|||
# default.units=default.units, |
|||
# name=name, gpbl=gpbl, gptr=gptr, vp=vp) |
|||
# if (draw) |
|||
# grid.draw(rg) |
|||
# invisible(rg) |
|||
# } |
@ -1,25 +0,0 @@ |
|||
#' Create United States Uniform Cartogram Heatmaps |
|||
#' |
|||
#' The cartogram heatmaps generated by the included methods |
|||
#' are an alternative to choropleth maps for the United States |
|||
#' and are based on work by the Washington Post graphics department in their report |
|||
#' on "The states most threatened by trade" |
|||
#' (<http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/>). |
|||
#' "State bins" preserve as much of the geographic placement of the states as |
|||
#' possible but have the look and feel of a traditional heatmap. Functions are |
|||
#' provided that allow for use of a binned, discrete scale, a continuous scale |
|||
#' or manually specified colors depending on what is needed for the underlying data. |
|||
#' |
|||
#' @md |
|||
#' @name statebins-package |
|||
#' @docType package |
|||
#' @author Bob Rudis (bob@@rud.is) |
|||
#' @importFrom grid unit |
|||
#' @importFrom scales alpha |
|||
#' @importFrom ggplot2 ggplot geom_tile scale_fill_manual guides geom_tile ggplotGrob |
|||
#' @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 margin %+replace% |
|||
#' @importFrom ggplot2 scale_fill_brewer ggtitle rel ggproto draw_key_polygon Geom Stat |
|||
NULL |
@ -1,93 +0,0 @@ |
|||
#' Create a new ggplot-based "statebin" chart for USA states/territories |
|||
#' |
|||
#' Pass in a data frame and get back a square choropleth. |
|||
#' |
|||
#' The `state_col` and `value_col` parameters default to `state` and `value`. That means |
|||
#' if you name the columns you want to plot with those names, you can forego passing them |
|||
#' in. Othersise, use `"strings"`. |
|||
#' |
|||
#' A _handy_ feature of this function is that you can specify a `dark_label` color |
|||
#' and a `light_label` color. What does that mean? Well, you also pass in the |
|||
#' color scale function you're going to use and `statebins` will apply it and use |
|||
#' that information to determine what the tile color is and --- if it's "dark" it will |
|||
#' use the `light_label` and if it's "light" it will use the `dark_label` color. That |
|||
#' means the labels will never blend in to the background (as long as you specify |
|||
#' decent label colors). |
|||
#' |
|||
#' You can customize the scale function you pass in by using name parameters. All named |
|||
#' parameters not used by `statebins()` itself get passed to the scale function. |
|||
#' |
|||
#' @md |
|||
#' @param state_data data frame of states and values to plot |
|||
#' @param state_col column name in \code{state_data} that has the states. no duplicates |
|||
#' and can be names (e.g. "\code{Maine}") or abbreviatons (e.g. "\code{ME}") |
|||
#' @param value_col column name in \code{state_data} that holds the values to be plotted |
|||
#' @param dark_label,light_label,na_label dark/light/NA label colors. The specified color will be used |
|||
#' when the algorithm determines labels should be inverted. |
|||
#' @param font_size font size (default = \code{3}) |
|||
#' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes |
|||
#' @param state_border_size border size |
|||
#' @param round rounded corners (default: `FALSE`) |
|||
#' @param radius if `round` is `TRUE` then use `grid::unit` to specify the corner radius. |
|||
#' Default is `grid::unit(6, "pt")` if using rounded corners. |
|||
#' @param ggplot2_scale_function ggplot2 scale function to use. Defaults to `scale_fill_distiller` |
|||
#' since you're likely passing in continuous data when you shouldn't be :-) |
|||
#' @param ... additional parameters to the scale function |
|||
#' @return ggplot2 object |
|||
#' @export |
|||
#' @examples |
|||
#' data(USArrests) |
|||
#' |
|||
#' USArrests$state <- rownames(USArrests) |
|||
#' statebins(USArrests, value_col="Assault", name = "Assault") + |
|||
#' theme_statebins(legend_position="right") |
|||
statebins <- function(state_data, |
|||
state_col="state", value_col="value", |
|||
dark_label="black", light_label="white", |
|||
na_label="white", font_size=3, |
|||
state_border_col="white", state_border_size=2, |
|||
round=FALSE, radius=grid::unit(6, "pt"), |
|||
ggplot2_scale_function=ggplot2::scale_fill_distiller, |
|||
...) { |
|||
|
|||
state_data <- data.frame(state_data, stringsAsFactors=FALSE) |
|||
|
|||
if (max(nchar(state_data[,state_col])) <= 3) { |
|||
merge.x <- "abbrev" |
|||
} else { |
|||
merge.x <- "state" |
|||
} |
|||
|
|||
state_data <- validate_states(state_data, state_col, merge.x) |
|||
|
|||
st.dat <- merge(state_coords, state_data, by.x=merge.x, by.y=state_col, all.y=TRUE, |
|||
sort=TRUE) |
|||
|
|||
gg <- ggplot() |
|||
|
|||
if (round) { |
|||
gg <- gg + geom_rtile(data = st.dat, radius = radius, |
|||
aes_string(x = "col", y = "row", fill = value_col), |
|||
color = state_border_col, size = state_border_size) |
|||
} else { |
|||
gg <- gg + geom_tile(data = st.dat, |
|||
aes_string(x = "col", y = "row", fill = value_col), |
|||
color = state_border_col, size = state_border_size) |
|||
} |
|||
|
|||
gg <- gg + scale_y_reverse() |
|||
gg <- gg + ggplot2_scale_function(...) |
|||
gg <- gg + coord_equal() |
|||
gg <- gg + labs(x = NULL, y = NULL) |
|||
|
|||
gb <- ggplot2::ggplot_build(gg) |
|||
|
|||
gg <- gg + geom_text(data = st.dat, |
|||
aes_string(x = "col", y = "row", label = "abbrev"), |
|||
angle = 0, |
|||
color = .sb_invert(gb$data[[1]]$fill, dark_label, light_label, na_label), |
|||
size = font_size) |
|||
|
|||
gg |
|||
|
|||
} |
@ -1,35 +0,0 @@ |
|||
#' Base statebins theme |
|||
#' |
|||
#' Clears out most of the cruft. Builds off of `theme_bw()` |
|||
#' |
|||
#' @md |
|||
#' @param legend_position fills in `legend.position` |
|||
#' @param base_family,base_size same as `theme_bw()` |
|||
#' @export |
|||
theme_statebins <- function(legend_position="bottom", |
|||
base_size = 11, |
|||
base_family = "") { |
|||
|
|||
gg <- theme_bw(base_size = base_size, base_family = base_family) |
|||
gg <- gg + 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(strip.background = element_rect(color="#2b2b2b", fill="white")) |
|||
gg <- gg + theme(plot.title=element_text(hjust=0.5, angle=0)) |
|||
gg <- gg + theme(axis.title.x=element_text(hjust=0.5, angle=0)) |
|||
gg <- gg + theme(legend.position=legend_position) |
|||
gg <- gg + theme(plot.title=element_text(size=16, hjust=0)) |
|||
gg <- gg + theme(plot.margin = margin(30,30,30,30)) |
|||
gg |
|||
|
|||
} |
@ -1,44 +0,0 @@ |
|||
.sb_invert <- function(hex_color, dark_color="black", light_color="white", |
|||
na_color="white") { |
|||
|
|||
hex_color <- gsub("#", "", hex_color) |
|||
|
|||
R <- suppressWarnings(as.integer(paste("0x", substr(hex_color,1,2), sep=""))) |
|||
G <- suppressWarnings(as.integer(paste("0x", substr(hex_color,3,4), sep=""))) |
|||
B <- suppressWarnings(as.integer(paste("0x", substr(hex_color,5,6), sep=""))) |
|||
|
|||
YIQ <- ((R*299) + (G*587) + (B*114)) / 1000 |
|||
|
|||
return( |
|||
ifelse(is.na(YIQ), na_color, |
|||
ifelse( |
|||
YIQ >= 128, dark_color, light_color) |
|||
) |
|||
) |
|||
} |
|||
|
|||
# sanity checks for state values |
|||
validate_states <- function(state_data, state_col, merge.x, ignore_dups=FALSE) { |
|||
|
|||
good_states <- state_data[,state_col] %in% state_coords[,merge.x] |
|||
if (any(!good_states)) { |
|||
invalid <- state_data[,state_col][which(!good_states)] |
|||
state_data <- state_data[which(good_states),] |
|||
warning("Found invalid state values: ", invalid) |
|||
} |
|||
|
|||
if (!ignore_dups) { |
|||
dups <- duplicated(state_data[,state_col]) |
|||
if (any(dups)) { |
|||
state_data <- state_data[which(!dups),] |
|||
warning("Removing duplicate state rows") |
|||
} |
|||
} |
|||
|
|||
return(state_data) |
|||
|
|||
} |
|||
|
|||
"%||%" <- function(a, b) { if (!is.null(a)) a else b } |
|||
|
|||
.pt <- 2.84527559055118 |
@ -1,192 +0,0 @@ |
|||
--- |
|||
output: rmarkdown::github_document |
|||
editor_options: |
|||
chunk_output_type: console |
|||
--- |
|||
|
|||
```{r pkg-knitr-opts, include=FALSE} |
|||
hrbrpkghelpr::global_opts() |
|||
``` |
|||
|
|||
```{r badges, results='asis', echo=FALSE, cache=FALSE} |
|||
hrbrpkghelpr::stinking_badges() |
|||
``` |
|||
|
|||
```{r description, results='asis', echo=FALSE, cache=FALSE} |
|||
hrbrpkghelpr::yank_title_and_description() |
|||
``` |
|||
|
|||
## What's Inside The Tin |
|||
|
|||
The following functions are implemented/datasets included: |
|||
|
|||
```{r ingredients, results='asis', echo=FALSE, cache=FALSE} |
|||
hrbrpkghelpr::describe_ingredients() |
|||
``` |
|||
|
|||
- `statebins`: (the original sole function in the package) Create a new ggplot-based "statebin" chart for USA states/territories |
|||
|
|||
## Installation |
|||
|
|||
```{r install-ex, results='asis', echo=FALSE, cache=FALSE} |
|||
hrbrpkghelpr::install_block() |
|||
``` |
|||
|
|||
## Usage |
|||
|
|||
All of the following examples use the [WaPo data](http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1). It looks like the columns they use are scaled data and I didn't take the time to figure out what they did, so the final figure just mimics their output (including the non-annotated legend). |
|||
|
|||
```{r setup} |
|||
library(statebins) |
|||
library(cdcfluview) |
|||
library(hrbrthemes) |
|||
library(tidyverse) |
|||
|
|||
# current verison |
|||
packageVersion("statebins") |
|||
``` |
|||
|
|||
### The original wapo data |
|||
|
|||
```{r original} |
|||
adat <- read_csv(system.file("extdata", "wapostates.csv", package="statebins")) |
|||
|
|||
mutate( |
|||
adat, |
|||
share = cut(avgshare94_00, breaks = 4, labels = c("0-1", "1-2", "2-3", "3-4")) |
|||
) %>% |
|||
statebins( |
|||
value_col = "share", |
|||
ggplot2_scale_function = scale_fill_brewer, |
|||
name = "Share of workforce with jobs lost or threatened by trade" |
|||
) + |
|||
labs(title = "1994-2000") + |
|||
theme_statebins() |
|||
``` |
|||
|
|||
### Continuous scale, legend on top |
|||
|
|||
```{r continuous} |
|||
statebins( |
|||
adat, |
|||
value_col = "avgshare01_07", |
|||
name = "Share of workforce with jobs lost or threatened by trade", |
|||
palette = "OrRd", |
|||
direction = 1 |
|||
) + |
|||
labs(x="2001-2007") + |
|||
theme_statebins(legend_position="top") |
|||
``` |
|||
|
|||
### Continuous scale, no legend |
|||
|
|||
```{r continuous_noleg} |
|||
statebins(adat, value_col = "avgshare08_12", palette = "Purples") + |
|||
labs(x="2008-2010") + |
|||
theme_statebins(legend_position = "none") |
|||
``` |
|||
|
|||
### Mortality data (has Puerto Rico) |
|||
|
|||
```{r mort} |
|||
# from: http://www.cdc.gov/nchs/fastats/state-and-territorial-data.htm |
|||
|
|||
dat <- read_csv(system.file("extdata", "deaths.csv", package="statebins")) |
|||
|
|||
statebins(dat, value_col = "death_rate", name="Per 100K pop") + |
|||
labs(title="Mortality Rate (2010)") + |
|||
theme_statebins() |
|||
``` |
|||
|
|||
### Fertility data |
|||
|
|||
```{r fert} |
|||
statebins(dat, value_col="fertility_rate", name="Per 100K pop", palette="PuBuGn") + |
|||
labs(title="Fertility Rate (2010)") + |
|||
theme_statebins() |
|||
``` |
|||
|
|||
### Manual - perhaps good for elections? |
|||
|
|||
```{r manual} |
|||
election_2012 <- suppressMessages(read_csv(system.file("extdata", "election2012.csv", package="statebins"))) |
|||
|
|||
mutate(election_2012, value = ifelse(is.na(Obama), "Romney", "Obama")) %>% |
|||
statebins( |
|||
font_size=4, dark_label = "white", light_label = "white", |
|||
ggplot2_scale_function = scale_fill_manual, |
|||
name = "Winner", |
|||
values = c(Romney = "#2166ac", Obama = "#b2182b") |
|||
) + |
|||
theme_statebins() |
|||
``` |
|||
|
|||
### Rounded rects! |
|||
|
|||
You can pass in a `grid::units()` call for the `radius` parameter. |
|||
|
|||
Slight curves: |
|||
|
|||
```{r rounded} |
|||
data(USArrests) |
|||
|
|||
USArrests$state <- rownames(USArrests) |
|||
statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE) + |
|||
theme_statebins(legend_position="right") |
|||
``` |
|||
|
|||
Circles! |
|||
|
|||
```{r rounded2} |
|||
statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE, |
|||
radius=grid::unit(16, "pt"), palette="Reds", direction=1) + |
|||
theme_statebins(legend_position="right") |
|||
``` |
|||
|
|||
### Geom |
|||
|
|||
```{r sb_facet, fig.width=20, fig.height=15} |
|||
flu <- ili_weekly_activity_indicators(2017) |
|||
|
|||
ggplot(flu, aes(state=statename, fill=activity_level)) + |
|||
geom_statebins() + |
|||
coord_equal() + |
|||
viridis::scale_fill_viridis( |
|||
name = "ILI Activity Level ", limits=c(0,10), breaks=0:10, option = "magma", direction = -1 |
|||
) + |
|||
facet_wrap(~weekend) + |
|||
labs(title="2017-18 Flu Season ILI Activity Level") + |
|||
theme_statebins(base_family = font_ps) + |
|||
theme(plot.title=element_text(size=16, hjust=0)) + |
|||
theme(plot.margin = margin(30,30,30,30)) |
|||
``` |
|||
|
|||
### All the "states" |
|||
|
|||
`statebins` now has PR, VI & NYC (by name or abbreviation) so you can use them, too: |
|||
|
|||
```{r all} |
|||
library(statebins) |
|||
library(tidyverse) |
|||
library(viridis) |
|||
|
|||
data(USArrests) |
|||
|
|||
# make up some data for the example |
|||
|
|||
rownames_to_column(USArrests, "state") %>% |
|||
bind_rows( |
|||
data_frame( |
|||
state = c("Virgin Islands", "Puerto Rico", "New York City"), |
|||
Murder = rep(mean(max(USArrests$Murder),3)), |
|||
Assault = rep(mean(max(USArrests$Assault),3)), |
|||
Rape = rep(mean(max(USArrests$Rape),3)), |
|||
UrbanPop = c(93, 95, 100) |
|||
) |
|||
) -> us_arrests |
|||
|
|||
statebins(us_arrests, value_col="Assault", |
|||
ggplot2_scale_function = viridis::scale_fill_viridis) + |
|||
labs(title="USArrests + made up data") + |
|||
theme_statebins("right") |
|||
``` |
@ -1,257 +0,0 @@ |
|||
|
|||
[![Project Status: Active – The project has reached a stable, usable |
|||
state and is being actively |
|||
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) |
|||
[![Signed |
|||
by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) |
|||
![Signed commit |
|||
%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg) |
|||
[![Linux build |
|||
Status](https://travis-ci.org/hrbrmstr/statebins.svg?branch=master)](https://travis-ci.org/hrbrmstr/statebins) |
|||
[![Windows build |
|||
status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/statebins?svg=true)](https://ci.appveyor.com/project/hrbrmstr/statebins) |
|||
[![Coverage |
|||
Status](https://codecov.io/gh/hrbrmstr/statebins/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/statebins) |
|||
[![cran |
|||
checks](https://cranchecks.info/badges/worst/statebins)](https://cranchecks.info/pkgs/statebins) |
|||
[![CRAN |
|||
status](https://www.r-pkg.org/badges/version/statebins)](https://www.r-pkg.org/pkg/statebins) |
|||
![Minimal R |
|||
Version](https://img.shields.io/badge/R%3E%3D-3.5.0-blue.svg) |
|||
![License](https://img.shields.io/badge/License-MIT-blue.svg) |
|||
|
|||
# statebins |
|||
|
|||
Create United States Uniform Cartogram Heatmaps |
|||
|
|||
## Description |
|||
|
|||
The cartogram heatmaps generated by the included methods are an |
|||
alternative to choropleth maps for the United States and are based on |
|||
work by the Washington Post graphics department in their report on “The |
|||
states most threatened by trade” |
|||
(<http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/>). |
|||
“State bins” preserve as much of the geographic placement of the states |
|||
as possible but have the look and feel of a traditional heatmap. |
|||
Functions are provided that allow for use of a binned, discrete scale, a |
|||
continuous scale or manually specified colors depending on what is |
|||
needed for the underlying data. |
|||
|
|||
## What’s Inside The Tin |
|||
|
|||
The following functions are implemented/datasets included: |
|||
|
|||
- `geom_statebins`: A statebins Geom |
|||
|
|||
- `state_tbl`: “State” abbreviation to name data frame |
|||
|
|||
- `theme_statebins`: Base statebins theme |
|||
|
|||
- `statebins`: (the original sole function in the package) Create a |
|||
new ggplot-based “statebin” chart for USA states/territories |
|||
|
|||
## Installation |
|||
|
|||
``` r |
|||
install.packages("statebins) # NOTE: CRAN version is 1.2.2 |
|||
# or |
|||
install.packages("statebins", repos = c("https://cinc.rud.is", "https://cloud.r-project.org/")) |
|||
# or |
|||
remotes::install_git("https://git.rud.is/hrbrmstr/statebins.git") |
|||
# or |
|||
remotes::install_git("https://git.sr.ht/~hrbrmstr/statebins") |
|||
# or |
|||
remotes::install_gitlab("hrbrmstr/statebins") |
|||
# or |
|||
remotes::install_bitbucket("hrbrmstr/statebins") |
|||
# or |
|||
remotes::install_github("hrbrmstr/statebins") |
|||
``` |
|||
|
|||
NOTE: To use the ‘remotes’ install options you will need to have the |
|||
[{remotes} package](https://github.com/r-lib/remotes) installed. |
|||
|
|||
## Usage |
|||
|
|||
All of the following examples use the [WaPo |
|||
data](http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1). |
|||
It looks like the columns they use are scaled data and I didn’t take the |
|||
time to figure out what they did, so the final figure just mimics their |
|||
output (including the non-annotated legend). |
|||
|
|||
``` r |
|||
library(statebins) |
|||
library(cdcfluview) |
|||
library(hrbrthemes) |
|||
library(tidyverse) |
|||
|
|||
# current verison |
|||
packageVersion("statebins") |
|||
## [1] '1.4.0' |
|||
``` |
|||
|
|||
### The original wapo data |
|||
|
|||
``` r |
|||
adat <- read_csv(system.file("extdata", "wapostates.csv", package="statebins")) |
|||
|
|||
mutate( |
|||
adat, |
|||
share = cut(avgshare94_00, breaks = 4, labels = c("0-1", "1-2", "2-3", "3-4")) |
|||
) %>% |
|||
statebins( |
|||
value_col = "share", |
|||
ggplot2_scale_function = scale_fill_brewer, |
|||
name = "Share of workforce with jobs lost or threatened by trade" |
|||
) + |
|||
labs(title = "1994-2000") + |
|||
theme_statebins() |
|||
``` |
|||
|
|||
<img src="man/figures/README-original-1.png" width="672" /> |
|||
|
|||
### Continuous scale, legend on top |
|||
|
|||
``` r |
|||
statebins( |
|||
adat, |
|||
value_col = "avgshare01_07", |
|||
name = "Share of workforce with jobs lost or threatened by trade", |
|||
palette = "OrRd", |
|||
direction = 1 |
|||
) + |
|||
labs(x="2001-2007") + |
|||
theme_statebins(legend_position="top") |
|||
``` |
|||
|
|||
<img src="man/figures/README-continuous-1.png" width="672" /> |
|||
|
|||
### Continuous scale, no legend |
|||
|
|||
``` r |
|||
statebins(adat, value_col = "avgshare08_12", palette = "Purples") + |
|||
labs(x="2008-2010") + |
|||
theme_statebins(legend_position = "none") |
|||
``` |
|||
|
|||
<img src="man/figures/README-continuous_noleg-1.png" width="672" /> |
|||
|
|||
### Mortality data (has Puerto Rico) |
|||
|
|||
``` r |
|||
# from: http://www.cdc.gov/nchs/fastats/state-and-territorial-data.htm |
|||
|
|||
dat <- read_csv(system.file("extdata", "deaths.csv", package="statebins")) |
|||
|
|||
statebins(dat, value_col = "death_rate", name="Per 100K pop") + |
|||
labs(title="Mortality Rate (2010)") + |
|||
theme_statebins() |
|||
``` |
|||
|
|||
<img src="man/figures/README-mort-1.png" width="672" /> |
|||
|
|||
### Fertility data |
|||
|
|||
``` r |
|||
statebins(dat, value_col="fertility_rate", name="Per 100K pop", palette="PuBuGn") + |
|||
labs(title="Fertility Rate (2010)") + |
|||
theme_statebins() |
|||
``` |
|||
|
|||
<img src="man/figures/README-fert-1.png" width="672" /> |
|||
|
|||
### Manual - perhaps good for elections? |
|||
|
|||
``` r |
|||
election_2012 <- suppressMessages(read_csv(system.file("extdata", "election2012.csv", package="statebins"))) |
|||
|
|||
mutate(election_2012, value = ifelse(is.na(Obama), "Romney", "Obama")) %>% |
|||
statebins( |
|||
font_size=4, dark_label = "white", light_label = "white", |
|||
ggplot2_scale_function = scale_fill_manual, |
|||
name = "Winner", |
|||
values = c(Romney = "#2166ac", Obama = "#b2182b") |
|||
) + |
|||
theme_statebins() |
|||
``` |
|||
|
|||
<img src="man/figures/README-manual-1.png" width="672" /> |
|||
|
|||
### Rounded rects\! |
|||
|
|||
You can pass in a `grid::units()` call for the `radius` parameter. |
|||
|
|||
Slight curves: |
|||
|
|||
``` r |
|||
data(USArrests) |
|||
|
|||
USArrests$state <- rownames(USArrests) |
|||
statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE) + |
|||
theme_statebins(legend_position="right") |
|||
``` |
|||
|
|||
<img src="man/figures/README-rounded-1.png" width="672" /> |
|||
|
|||
Circles\! |
|||
|
|||
``` r |
|||
statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE, |
|||
radius=grid::unit(16, "pt"), palette="Reds", direction=1) + |
|||
theme_statebins(legend_position="right") |
|||
``` |
|||
|
|||
<img src="man/figures/README-rounded2-1.png" width="672" /> |
|||
|
|||
### Geom |
|||
|
|||
``` r |
|||
flu <- ili_weekly_activity_indicators(2017) |
|||
|
|||
ggplot(flu, aes(state=statename, fill=activity_level)) + |
|||
geom_statebins() + |
|||
coord_equal() + |
|||
viridis::scale_fill_viridis( |
|||
name = "ILI Activity Level ", limits=c(0,10), breaks=0:10, option = "magma", direction = -1 |
|||
) + |
|||
facet_wrap(~weekend) + |
|||
labs(title="2017-18 Flu Season ILI Activity Level") + |
|||
theme_statebins(base_family = font_ps) + |
|||
theme(plot.title=element_text(size=16, hjust=0)) + |
|||
theme(plot.margin = margin(30,30,30,30)) |
|||
``` |
|||
|
|||
<img src="man/figures/README-sb_facet-1.png" width="1920" /> |
|||
|
|||
### All the “states” |
|||
|
|||
`statebins` now has PR, VI & NYC (by name or abbreviation) so you can |
|||
use them, too: |
|||
|
|||
``` r |
|||
library(statebins) |
|||
library(tidyverse) |
|||
library(viridis) |
|||
|
|||
data(USArrests) |
|||
|
|||
# make up some data for the example |
|||
|
|||
rownames_to_column(USArrests, "state") %>% |
|||
bind_rows( |
|||
data_frame( |
|||
state = c("Virgin Islands", "Puerto Rico", "New York City"), |
|||
Murder = rep(mean(max(USArrests$Murder),3)), |
|||
Assault = rep(mean(max(USArrests$Assault),3)), |
|||
Rape = rep(mean(max(USArrests$Rape),3)), |
|||
UrbanPop = c(93, 95, 100) |
|||
) |
|||
) -> us_arrests |
|||
|
|||
statebins(us_arrests, value_col="Assault", |
|||
ggplot2_scale_function = viridis::scale_fill_viridis) + |
|||
labs(title="USArrests + made up data") + |
|||
theme_statebins("right") |
|||
``` |
|||
|
|||
<img src="man/figures/README-all-1.png" width="672" /> |
@ -1,45 +0,0 @@ |
|||
# DO NOT CHANGE the "init" and "install" sections below |
|||
|
|||
# Download script file from GitHub |
|||
init: |
|||
ps: | |
|||
$ErrorActionPreference = "Stop" |
|||
Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" |
|||
Import-Module '..\appveyor-tool.ps1' |
|||
|
|||
install: |
|||
ps: Bootstrap |
|||
|
|||
cache: |
|||
- C:\RLibrary |
|||
|
|||
# Adapt as necessary starting from here |
|||
|
|||
build_script: |
|||
- travis-tool.sh install_deps |
|||
|
|||
test_script: |
|||
- travis-tool.sh run_tests |
|||
|
|||
on_failure: |
|||
- 7z a failure.zip *.Rcheck\* |
|||
- appveyor PushArtifact failure.zip |
|||
|
|||
artifacts: |
|||
- path: '*.Rcheck\**\*.log' |
|||
name: Logs |
|||
|
|||
- path: '*.Rcheck\**\*.out' |
|||
name: Logs |
|||
|
|||
- path: '*.Rcheck\**\*.fail' |
|||
name: Logs |
|||
|
|||
- path: '*.Rcheck\**\*.Rout' |
|||
name: Logs |
|||
|
|||
- path: '\*_*.tar.gz' |
|||
name: Bits |
|||
|
|||
- path: '\*_*.zip' |
|||
name: Bits |
@ -1,12 +0,0 @@ |
|||
comment: false |
|||
|
|||
coverage: |
|||
status: |
|||
project: |
|||
default: |
|||
target: auto |
|||
threshold: 1% |
|||
patch: |
|||
default: |
|||
target: auto |
|||
threshold: 1% |
@ -1,31 +0,0 @@ |
|||
## Why an update? |
|||
* fix issues identified by CRAN |
|||
* compatibility with new ggplot2 |
|||
|
|||
## FIXED the DESCRIPTION error noted by Kurt |
|||
|
|||
## ALSO NOTE that these words are *not* mis-spelled. |
|||
|
|||
Cartogram (3:19) |
|||
Choropleth (3:62) |
|||
Heatmaps (3:29) |
|||
choropleth (9:45) |
|||
statebins (9:14, 11:47) |
|||
|
|||
## Test environments |
|||
* local OS X install (devel and release) |
|||
* ubuntu 12.04 (on travis-ci), R |
|||
* win-builder (devel and release) |
|||
|
|||
## R CMD check results |
|||
There were no ERRORs or WARNINGs. |
|||
|
|||
One NOTE: |
|||
|
|||
Maintainer: ‘Bob Rudis <bob@rudis.net> |
|||
|
|||
License components with restrictions and base license permitting such: |
|||
MIT + file LICENSE |
|||
File 'LICENSE': |
|||
YEAR: 2015 |
|||
COPYRIGHT HOLDER: Bob Rudis |
@ -1,24 +0,0 @@ |
|||
## code to prepare `DATASET` dataset goes here |
|||
|
|||
state_tbl <- structure(list(abbrev = c("AL", "AK", "AZ", "AR", "CA", "CO", |
|||
"CT", "DC", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", |
|||
"KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", |
|||
"NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", |
|||
"RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY", |
|||
"PR", "VI", "NYC"), |
|||
state = c("Alabama", "Alaska", "Arizona", "Arkansas", |
|||
"California", "Colorado", "Connecticut", "District of Columbia", |
|||
"Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", |
|||
"Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", |
|||
"Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", |
|||
"Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", |
|||
"New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", |
|||
"Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", |
|||
"South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", |
|||
"Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming", |
|||
"Puerto Rico", "Virgin Islands", "New York City")), |
|||
.Names = c("abbrev", "state"), |
|||
class = "data.frame", row.names = c(NA, -54L)) |
|||
|
|||
|
|||
usethis::use_data(state_tbl, overwrite = TRUE) |
After Width: | Height: | Size: 216 B |
After Width: | Height: | Size: 108 B |
After Width: | Height: | Size: 357 B |
@ -0,0 +1,188 @@ |
|||
<!doctype html> |
|||
<html> |
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="chrome=1"> |
|||
<title>statebins by hrbrmstr</title> |
|||
|
|||
<link rel="stylesheet" href="stylesheets/styles.css"> |
|||
<link rel="stylesheet" href="stylesheets/pygment_trac.css"> |
|||
<script src="javascripts/scale.fix.js"></script> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> |
|||
|
|||
<!--[if lt IE 9]> |
|||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
|||
<![endif]--> |
|||
</head> |
|||
<body> |
|||
<div class="wrapper"> |
|||
<header> |
|||
<h1>statebins</h1> |
|||
<p>U.S. State Cartogram Heatmaps in R; an alternative to choropleths of US States ala http://bit.ly/statebins</p> |
|||
<p class="view"><a href="https://github.com/hrbrmstr/statebins">View the Project on GitHub <small>hrbrmstr/statebins</small></a></p> |
|||
<ul> |
|||
<li><a href="https://github.com/hrbrmstr/statebins/zipball/master">Download <strong>ZIP File</strong></a></li> |
|||
<li><a href="https://github.com/hrbrmstr/statebins/tarball/master">Download <strong>TAR Ball</strong></a></li> |
|||
<li><a href="https://github.com/hrbrmstr/statebins">View On <strong>GitHub</strong></a></li> |
|||
</ul> |
|||
</header> |
|||
<section> |
|||
<p>statebins is an alternative to choropleth maps for USA States</p> |
|||
|
|||
<p>The following functions are implemented:</p> |
|||
|
|||
<ul> |
|||
<li> <code>statebins</code> - creates "statebin" charts in the style of <a href="http://bit.ly/statebins">http://bit.ly/statebins</a> - This version uses discrete <code>RColorBrewer</code> scales, binned by the "breaks" parameter.</li> |
|||
<li> <code>statebins_continuous</code> - creates "statebin" charts in the style of <a href="http://bit.ly/statebins">http://bit.ly/statebins</a> - This version uses a continuous scale based on <code>RColorBrewer</code> scales (passing in a 6 element <code>RColorBrewer</code> palette to <code>scale_fill_gradientn</code>).</li> |
|||
</ul> |
|||
|
|||
<h3> |
|||
<a id="todo" class="anchor" href="#todo" aria-hidden="true"><span class="octicon octicon-link"></span></a>TODO</h3> |
|||
|
|||
<ul> |
|||
<li> The current version is usable, but I think the plot margins and the legends need work</li> |
|||
<li> Apply algorithm to switch to light-on-dark depending on the background tile color</li> |
|||
</ul> |
|||
|
|||
<h3> |
|||
<a id="news" class="anchor" href="#news" aria-hidden="true"><span class="octicon octicon-link"></span></a>News</h3> |
|||
|
|||
<ul> |
|||
<li> Version <code>1.0.0</code> released</li> |
|||
</ul> |
|||
|
|||
<h3> |
|||
<a id="installation" class="anchor" href="#installation" aria-hidden="true"><span class="octicon octicon-link"></span></a>Installation</h3> |
|||
|
|||
<div class="highlight highlight-r"><pre><span class="pl-e">devtools</span><span class="pl-k">::</span>install_github(<span class="pl-s1"><span class="pl-pds">"</span>hrbrmstr/statebins<span class="pl-pds">"</span></span>)</pre></div> |
|||
|
|||
<h3> |
|||
<a id="usage" class="anchor" href="#usage" aria-hidden="true"><span class="octicon octicon-link"></span></a>Usage</h3> |
|||
|
|||
<p>All of the following examples use the <a href="http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1">WaPo data</a>. It looks like the columns they use are scaled data and I didn't take the time to figure out what they did, so the final figure just mimics their output (including the non-annotated legend).</p> |
|||
|
|||
<div class="highlight highlight-r"><pre>library(<span class="pl-vo">statebins</span>) |
|||
|
|||
<span class="pl-c"># current verison</span> |
|||
packageVersion(<span class="pl-s1"><span class="pl-pds">"</span>statebins<span class="pl-pds">"</span></span>)</pre></div> |
|||
|
|||
<pre><code>## [1] '1.0' |
|||
</code></pre> |
|||
|
|||
<div class="highlight highlight-r"><pre><span class="pl-c"># the original wapo data</span> |
|||
|
|||
<span class="pl-vo">dat</span> <span class="pl-k"><-</span> read.csv(<span class="pl-s1"><span class="pl-pds">"</span>http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1<span class="pl-pds">"</span></span>, <span class="pl-v">stringsAsFactors</span><span class="pl-k">=</span><span class="pl-c1">FALSE</span>) |
|||
|
|||
<span class="pl-vo">gg</span> <span class="pl-k"><-</span> statebins(<span class="pl-vo">dat</span>, <span class="pl-s1"><span class="pl-pds">"</span>state<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>avgshare94_00<span class="pl-pds">"</span></span>, <span class="pl-v">breaks</span><span class="pl-k">=</span><span class="pl-c1">4</span>, |
|||
<span class="pl-v">labels</span><span class="pl-k">=</span>c(<span class="pl-s1"><span class="pl-pds">"</span>0-1<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>1-2<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>2-3<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>3-4<span class="pl-pds">"</span></span>), |
|||
<span class="pl-v">legend_title</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>Share of workforce with jobs lost or threatened by trade<span class="pl-pds">"</span></span>, <span class="pl-v">font_size</span><span class="pl-k">=</span><span class="pl-c1">3</span>, |
|||
<span class="pl-v">brewer_pal</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>Blues<span class="pl-pds">"</span></span>, <span class="pl-v">text_color</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>black<span class="pl-pds">"</span></span>, |
|||
<span class="pl-v">plot_title</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>1994-2000<span class="pl-pds">"</span></span>, <span class="pl-v">title_position</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>bottom<span class="pl-pds">"</span></span>) |
|||
|
|||
<span class="pl-vo">gg</span></pre></div> |
|||
|
|||
<p><img src="https://raw.githubusercontent.com/hrbrmstr/statebins/master/README_files/figure-markdown_github/unnamed-chunk-31.png" alt="plot of chunk unnamed-chunk-3"></p> |
|||
|
|||
<div class="highlight highlight-r"><pre><span class="pl-c"># continuous scale, legend on top</span> |
|||
|
|||
<span class="pl-vo">gg2</span> <span class="pl-k"><-</span> statebins_continuous(<span class="pl-vo">dat</span>, <span class="pl-s1"><span class="pl-pds">"</span>state<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>avgshare01_07<span class="pl-pds">"</span></span>, |
|||
<span class="pl-v">legend_title</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>Share of workforce with jobs lost or threatened by trade<span class="pl-pds">"</span></span>, <span class="pl-v">legend_position</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>top<span class="pl-pds">"</span></span>, |
|||
<span class="pl-v">brewer_pal</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>OrRd<span class="pl-pds">"</span></span>, <span class="pl-v">text_color</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>black<span class="pl-pds">"</span></span>, <span class="pl-v">font_size</span><span class="pl-k">=</span><span class="pl-c1">3</span>, |
|||
<span class="pl-v">plot_title</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>2001-2007<span class="pl-pds">"</span></span>, <span class="pl-v">title_position</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>bottom<span class="pl-pds">"</span></span>) |
|||
|
|||
<span class="pl-vo">gg2</span></pre></div> |
|||
|
|||
<p><img src="https://raw.githubusercontent.com/hrbrmstr/statebins/master/README_files/figure-markdown_github/unnamed-chunk-32.png" alt="plot of chunk unnamed-chunk-3"></p> |
|||
|
|||
<div class="highlight highlight-r"><pre><span class="pl-c"># continuous scale, no legend</span> |
|||
|
|||
<span class="pl-vo">gg3</span> <span class="pl-k"><-</span> statebins_continuous(<span class="pl-vo">dat</span>, <span class="pl-s1"><span class="pl-pds">"</span>state<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>avgshare08_12<span class="pl-pds">"</span></span>, |
|||
<span class="pl-v">legend_title</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>States<span class="pl-pds">"</span></span>, <span class="pl-v">legend_position</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>none<span class="pl-pds">"</span></span>, |
|||
<span class="pl-v">brewer_pal</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>Purples<span class="pl-pds">"</span></span>, <span class="pl-v">text_color</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>black<span class="pl-pds">"</span></span>, <span class="pl-v">font_size</span><span class="pl-k">=</span><span class="pl-c1">3</span>, |
|||
<span class="pl-v">plot_title</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>2008-2012<span class="pl-pds">"</span></span>, <span class="pl-v">title_position</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>bottom<span class="pl-pds">"</span></span>) |
|||
|
|||
<span class="pl-vo">gg3</span></pre></div> |
|||
|
|||
<p><img src="https://raw.githubusercontent.com/hrbrmstr/statebins/master/README_files/figure-markdown_github/unnamed-chunk-33.png" alt="plot of chunk unnamed-chunk-3"></p> |
|||
|
|||
<div class="highlight highlight-r"><pre><span class="pl-c"># or, more like the one in the WaPo article; i might be picking the wrong columns here. it's just for an example</span> |
|||
|
|||
<span class="pl-en">sb</span> <span class="pl-k"><-</span> <span class="pl-k">function</span>(<span class="pl-vo">col</span>, <span class="pl-vo">title</span>) { |
|||
statebins(<span class="pl-vo">dat</span>, <span class="pl-s1"><span class="pl-pds">"</span>state<span class="pl-pds">"</span></span>,<span class="pl-vo">col</span>, <span class="pl-v">brewer_pal</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>Blues<span class="pl-pds">"</span></span>, <span class="pl-v">text_color</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>black<span class="pl-pds">"</span></span>, <span class="pl-v">legend_position</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>none<span class="pl-pds">"</span></span>, <span class="pl-v">font_size</span><span class="pl-k">=</span><span class="pl-c1">3</span>, <span class="pl-v">plot_title</span><span class="pl-k">=</span><span class="pl-vo">title</span>, <span class="pl-v">breaks</span><span class="pl-k">=</span><span class="pl-c1">4</span>, <span class="pl-v">labels</span><span class="pl-k">=</span><span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">4</span>) |
|||
}</pre></div> |
|||
|
|||
<div class="highlight highlight-r"><pre><span class="pl-c"># cheating and using <table> to arrange them below and also making a WaPo-like legend, </span> |
|||
<span class="pl-c"># since mucking with grid graphics margins/padding was not an option time-wise at the moment</span> |
|||
|
|||
sb(<span class="pl-s1"><span class="pl-pds">"</span>avgshare94_00<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>1994-2000<span class="pl-pds">"</span></span>) |
|||
sb(<span class="pl-s1"><span class="pl-pds">"</span>avgshare01_07<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>2001-2007<span class="pl-pds">"</span></span>) |
|||
sb(<span class="pl-s1"><span class="pl-pds">"</span>avgshare08_12<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>2008-2012<span class="pl-pds">"</span></span>)</pre></div> |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
<p></p> |
|||
<img src="https://raw.githubusercontent.com/hrbrmstr/statebins/master/tmp/statebins-composite.png" alt="img"> |
|||
|
|||
|
|||
<p>And, we'll throw in a gratuitous animation for good measure:</p> |
|||
|
|||
<div class="highlight highlight-r"><pre><span class="pl-c"># data set from StatsAmerica - http://www.statsamerica.org/profiles/sip_index.html</span> |
|||
|
|||
<span class="pl-c"># median household income from the ACS survey</span> |
|||
<span class="pl-vo">miacs</span> <span class="pl-k"><-</span> read.csv(<span class="pl-s1"><span class="pl-pds">"</span>http://dds.ec/data/median-income-acs.csv<span class="pl-pds">"</span></span>, <span class="pl-v">header</span><span class="pl-k">=</span><span class="pl-c1">TRUE</span>, <span class="pl-v">stringsAsFactors</span><span class="pl-k">=</span><span class="pl-c1">FALSE</span>) |
|||
|
|||
<span class="pl-c"># generate frames based on year</span> |
|||
sapply(unique(<span class="pl-vo">miacs</span><span class="pl-k">$</span><span class="pl-vo">year</span>), <span class="pl-k">function</span>(<span class="pl-vo">year</span>) { |
|||
|
|||
png(<span class="pl-v">file</span><span class="pl-k">=</span>sprintf(<span class="pl-s1"><span class="pl-pds">"</span>tmp/household%d.png<span class="pl-pds">"</span></span>, <span class="pl-vo">year</span>), |
|||
<span class="pl-v">type</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>quartz<span class="pl-pds">"</span></span>, <span class="pl-v">antialias</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>subpixel<span class="pl-pds">"</span></span>, <span class="pl-v">width</span><span class="pl-k">=</span><span class="pl-c1">800</span>, <span class="pl-v">height</span><span class="pl-k">=</span><span class="pl-c1">600</span>) |
|||
|
|||
<span class="pl-vo">rng</span> <span class="pl-k"><-</span> floor(range(<span class="pl-vo">miacs</span>[<span class="pl-vo">miacs</span><span class="pl-k">$</span><span class="pl-vo">year</span><span class="pl-k">==</span><span class="pl-vo">year</span>,]<span class="pl-k">$</span><span class="pl-vo">mh_inc</span>)) |
|||
|
|||
<span class="pl-vo">ggtmp</span> <span class="pl-k"><-</span> statebins(<span class="pl-vo">miacs</span>[<span class="pl-vo">miacs</span><span class="pl-k">$</span><span class="pl-vo">year</span><span class="pl-k">==</span><span class="pl-vo">year</span>,], <span class="pl-s1"><span class="pl-pds">"</span>state<span class="pl-pds">"</span></span>, <span class="pl-s1"><span class="pl-pds">"</span>mh_inc<span class="pl-pds">"</span></span>, |
|||
<span class="pl-v">legend_title</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>States<span class="pl-pds">"</span></span>, <span class="pl-v">legend_position</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>none<span class="pl-pds">"</span></span>, |
|||
<span class="pl-v">brewer_pal</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>Greens<span class="pl-pds">"</span></span>, <span class="pl-v">text_color</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>black<span class="pl-pds">"</span></span>, <span class="pl-v">font_size</span><span class="pl-k">=</span><span class="pl-c1">3</span>, |
|||
<span class="pl-v">plot_title</span><span class="pl-k">=</span>sprintf(<span class="pl-s1"><span class="pl-pds">"</span>Median Household Income (ACS) %d<span class="pl-cce">\n</span>$%s - $%s<span class="pl-pds">"</span></span>, <span class="pl-vo">year</span>, comma(<span class="pl-vo">rng</span>[<span class="pl-c1">1</span>]), comma(<span class="pl-vo">rng</span>[<span class="pl-c1">2</span>])), <span class="pl-v">title_position</span><span class="pl-k">=</span><span class="pl-s1"><span class="pl-pds">"</span>top<span class="pl-pds">"</span></span>) |
|||
|
|||
print(<span class="pl-vo">ggtmp</span>) |
|||
|
|||
dev.off() |
|||
|
|||
}) |
|||
|
|||
<span class="pl-c"># animate them with ImageMagick</span> |
|||
system(<span class="pl-s1"><span class="pl-pds">"</span>convert -background white -alpha remove -layers OptimizePlus -delay 150 tmp/*.png -loop 1 tmp/household.gif<span class="pl-pds">"</span></span>)</pre></div> |
|||
|
|||
<p></p> |
|||
<img src="https://raw.githubusercontent.com/hrbrmstr/statebins/master/tmp/household.gif" alt="img"> |
|||
|
|||
|
|||
<h3> |
|||
<a id="test-results" class="anchor" href="#test-results" aria-hidden="true"><span class="octicon octicon-link"></span></a>Test Results</h3> |
|||
|
|||
<div class="highlight highlight-r"><pre>library(<span class="pl-vo">statebins</span>) |
|||
library(<span class="pl-vo">testthat</span>) |
|||
|
|||
date()</pre></div> |
|||
|
|||
<pre><code>## [1] "Tue Aug 26 17:53:56 2014" |
|||
</code></pre> |
|||
|
|||
<div class="highlight highlight-r"><pre>test_dir(<span class="pl-s1"><span class="pl-pds">"</span>tests/<span class="pl-pds">"</span></span>)</pre></div> |
|||
|
|||
<pre><code>## basic functionality : |
|||
</code></pre> |
|||
</section> |
|||
</div> |
|||
<footer> |
|||
<p>Project maintained by <a href="https://github.com/hrbrmstr">hrbrmstr</a></p> |
|||
<p>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a></p> |
|||
</footer> |
|||
<!--[if !IE]><script>fixScale(document);</script><![endif]--> |
|||
|
|||
</body> |
|||
</html> |
|
|
@ -0,0 +1,20 @@ |
|||
fixScale = function(doc) { |
|||
|
|||
var addEvent = 'addEventListener', |
|||
type = 'gesturestart', |
|||
qsa = 'querySelectorAll', |
|||
scales = [1, 1], |
|||
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : []; |
|||
|
|||
function fix() { |
|||
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1]; |
|||
doc.removeEventListener(type, fix, true); |
|||
} |
|||
|
|||
if ((meta = meta[meta.length - 1]) && addEvent in doc) { |
|||
fix(); |
|||
scales = [.25, 1.6]; |
|||
doc[addEvent](type, fix, true); |
|||
} |
|||
|
|||
}; |
Before Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 634 KiB |
@ -1,113 +0,0 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/geom-statebins.r |
|||
\docType{data} |
|||
\name{geom_statebins} |
|||
\alias{geom_statebins} |
|||
\alias{GeomStatebins} |
|||
\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", |
|||
border_size = 2, |
|||
lbl_size = 3, |
|||
dark_lbl = "black", |
|||
light_lbl = "white", |
|||
radius = grid::unit(6, "pt"), |
|||
..., |
|||
na.rm = FALSE, |
|||
show.legend = NA, |
|||
inherit.aes = TRUE |
|||
) |
|||
|
|||
GeomStatebins |
|||
} |
|||
\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}"} |
|||
|
|||
\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) |
|||
} |
|||
} |
|||
\examples{ |
|||
\dontrun{ |
|||
library(statebins) |
|||
library(cdcfluview) |
|||
library(hrbrthemes) |
|||
library(tidyverse) |
|||
|
|||
flu <- ili_weekly_activity_indicators(2017) |
|||
|
|||
ggplot(flu, aes(state=statename, fill=activity_level)) + |
|||
geom_statebins() + |
|||
coord_equal() + |
|||
viridis::scale_fill_viridis( |
|||
name = "ILI Activity Level ", limits=c(0,10), breaks=0:10, option = "magma", direction = -1 |
|||
) + |
|||
facet_wrap(~weekend) + |
|||
labs(title="2017-18 Flu Season ILI Activity Level") + |
|||
theme_statebins(base_family = font_ps) + |
|||
theme(plot.title=element_text(size=16, hjust=0)) + |
|||
theme(plot.margin = margin(30,30,30,30)) |
|||
} |
|||
} |
|||
\keyword{datasets} |
@ -1,9 +0,0 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/aaa.R |
|||
\docType{data} |
|||
\name{state_tbl} |
|||
\alias{state_tbl} |
|||
\title{"State" abbreviation to name data frame} |
|||
\description{ |
|||
"State" abbreviation to name data frame |
|||
} |
@ -1,20 +0,0 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/statebins-package.R |
|||
\docType{package} |
|||
\name{statebins-package} |
|||
\alias{statebins-package} |
|||
\title{Create United States Uniform Cartogram Heatmaps} |
|||
\description{ |
|||
The cartogram heatmaps generated by the included methods |
|||
are an alternative to choropleth maps for the United States |
|||
and are based on work by the Washington Post graphics department in their report |
|||
on "The states most threatened by trade" |
|||
(\url{http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/}). |
|||
"State bins" preserve as much of the geographic placement of the states as |
|||
possible but have the look and feel of a traditional heatmap. Functions are |
|||
provided that allow for use of a binned, discrete scale, a continuous scale |
|||
or manually specified colors depending on what is needed for the underlying data. |
|||
} |
|||
\author{ |
|||
Bob Rudis (bob@rud.is) |
|||
} |
@ -1,78 +0,0 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/statebins.R |
|||
\name{statebins} |
|||
\alias{statebins} |
|||
\title{Create a new ggplot-based "statebin" chart for USA states/territories} |
|||
\usage{ |
|||
statebins( |
|||
state_data, |
|||
state_col = "state", |
|||
value_col = "value", |
|||
dark_label = "black", |
|||
light_label = "white", |
|||
na_label = "white", |
|||
font_size = 3, |
|||
state_border_col = "white", |
|||
state_border_size = 2, |
|||
round = FALSE, |
|||
radius = grid::unit(6, "pt"), |
|||
ggplot2_scale_function = ggplot2::scale_fill_distiller, |
|||
... |
|||
) |
|||
} |
|||
\arguments{ |
|||
\item{state_data}{data frame of states and values to plot} |
|||
|
|||
\item{state_col}{column name in \code{state_data} that has the states. no duplicates |
|||
and can be names (e.g. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")} |
|||
|
|||
\item{value_col}{column name in \code{state_data} that holds the values to be plotted} |
|||
|
|||
\item{dark_label, light_label, na_label}{dark/light/NA label colors. The specified color will be used |
|||
when the algorithm determines labels should be inverted.} |
|||
|
|||
\item{font_size}{font size (default = \code{3})} |
|||
|
|||
\item{state_border_col}{default "\code{white}" - this creates the "spaces" between boxes} |
|||
|
|||
\item{state_border_size}{border size} |
|||
|
|||
\item{round}{rounded corners (default: \code{FALSE})} |
|||
|
|||
\item{radius}{if \code{round} is \code{TRUE} then use \code{grid::unit} to specify the corner radius. |
|||
Default is \code{grid::unit(6, "pt")} if using rounded corners.} |
|||
|
|||
\item{ggplot2_scale_function}{ggplot2 scale function to use. Defaults to \code{scale_fill_distiller} |
|||
since you're likely passing in continuous data when you shouldn't be :-)} |
|||
|
|||
\item{...}{additional parameters to the scale function} |
|||
} |
|||
\value{ |
|||
ggplot2 object |
|||
} |
|||
\description{ |
|||
Pass in a data frame and get back a square choropleth. |
|||
} |
|||
\details{ |
|||
The \code{state_col} and \code{value_col} parameters default to \code{state} and \code{value}. That means |
|||
if you name the columns you want to plot with those names, you can forego passing them |
|||
in. Othersise, use \code{"strings"}. |
|||
|
|||
A \emph{handy} feature of this function is that you can specify a \code{dark_label} color |
|||
and a \code{light_label} color. What does that mean? Well, you also pass in the |
|||
color scale function you're going to use and \code{statebins} will apply it and use |
|||
that information to determine what the tile color is and --- if it's "dark" it will |
|||
use the \code{light_label} and if it's "light" it will use the \code{dark_label} color. That |
|||
means the labels will never blend in to the background (as long as you specify |
|||
decent label colors). |
|||
|
|||
You can customize the scale function you pass in by using name parameters. All named |
|||
parameters not used by \code{statebins()} itself get passed to the scale function. |
|||
} |
|||
\examples{ |
|||
data(USArrests) |
|||
|
|||
USArrests$state <- rownames(USArrests) |
|||
statebins(USArrests, value_col="Assault", name = "Assault") + |
|||
theme_statebins(legend_position="right") |
|||
} |
@ -1,16 +0,0 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/theme-statebin.R |
|||
\name{theme_statebins} |
|||
\alias{theme_statebins} |
|||
\title{Base statebins theme} |
|||
\usage{ |
|||
theme_statebins(legend_position = "bottom", base_size = 11, base_family = "") |
|||
} |
|||
\arguments{ |
|||
\item{legend_position}{fills in \code{legend.position}} |
|||
|
|||
\item{base_family, base_size}{same as \code{theme_bw()}} |
|||
} |
|||
\description{ |
|||
Clears out most of the cruft. Builds off of \code{theme_bw()} |
|||
} |
@ -1,22 +0,0 @@ |
|||
Version: 1.0 |
|||
|
|||
RestoreWorkspace: Default |
|||
SaveWorkspace: Default |
|||
AlwaysSaveHistory: Default |
|||
|
|||
EnableCodeIndexing: Yes |
|||
UseSpacesForTab: Yes |
|||
NumSpacesForTab: 2 |
|||
Encoding: UTF-8 |
|||
|
|||
RnwWeave: Sweave |
|||
LaTeX: pdfLaTeX |
|||
|
|||
StripTrailingWhitespace: Yes |
|||
|
|||
BuildType: Package |
|||
PackageUseDevtools: Yes |
|||
PackageInstallArgs: --no-multiarch --with-keep.source |
|||
PackageBuildArgs: --resave-data |
|||
PackageCheckArgs: --as-cran |
|||
PackageRoxygenize: rd,collate,namespace |
@ -0,0 +1,60 @@ |
|||
.highlight .hll { background-color: #49483e } |
|||
.highlight { background: #3A3C42; color: #f8f8f2 } |
|||
.highlight .c { color: #75715e } /* Comment */ |
|||
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */ |
|||
.highlight .k { color: #66d9ef } /* Keyword */ |
|||
.highlight .l { color: #ae81ff } /* Literal */ |
|||
.highlight .n { color: #f8f8f2 } /* Name */ |
|||
.highlight .o { color: #f92672 } /* Operator */ |
|||
.highlight .p { color: #f8f8f2 } /* Punctuation */ |
|||
.highlight .cm { color: #75715e } /* Comment.Multiline */ |
|||
.highlight .cp { color: #75715e } /* Comment.Preproc */ |
|||
.highlight .c1 { color: #75715e } /* Comment.Single */ |
|||
.highlight .cs { color: #75715e } /* Comment.Special */ |
|||
.highlight .ge { font-style: italic } /* Generic.Emph */ |
|||
.highlight .gs { font-weight: bold } /* Generic.Strong */ |
|||
.highlight .kc { color: #66d9ef } /* Keyword.Constant */ |
|||
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */ |
|||
.highlight .kn { color: #f92672 } /* Keyword.Namespace */ |
|||
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */ |
|||
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */ |
|||
.highlight .kt { color: #66d9ef } /* Keyword.Type */ |
|||
.highlight .ld { color: #e6db74 } /* Literal.Date */ |
|||
.highlight .m { color: #ae81ff } /* Literal.Number */ |
|||
.highlight .s { color: #e6db74 } /* Literal.String */ |
|||
.highlight .na { color: #a6e22e } /* Name.Attribute */ |
|||
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */ |
|||
.highlight .nc { color: #a6e22e } /* Name.Class */ |
|||
.highlight .no { color: #66d9ef } /* Name.Constant */ |
|||
.highlight .nd { color: #a6e22e } /* Name.Decorator */ |
|||
.highlight .ni { color: #f8f8f2 } /* Name.Entity */ |
|||
.highlight .ne { color: #a6e22e } /* Name.Exception */ |
|||
.highlight .nf { color: #a6e22e } /* Name.Function */ |
|||
.highlight .nl { color: #f8f8f2 } /* Name.Label */ |
|||
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */ |
|||
.highlight .nx { color: #a6e22e } /* Name.Other */ |
|||
.highlight .py { color: #f8f8f2 } /* Name.Property */ |
|||
.highlight .nt { color: #f92672 } /* Name.Tag */ |
|||
.highlight .nv { color: #f8f8f2 } /* Name.Variable */ |
|||
.highlight .ow { color: #f92672 } /* Operator.Word */ |
|||
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */ |
|||
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */ |
|||
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ |
|||
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ |
|||
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ |
|||
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ |
|||
.highlight .sc { color: #e6db74 } /* Literal.String.Char */ |
|||
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */ |
|||
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */ |
|||
.highlight .se { color: #ae81ff } /* Literal.String.Escape */ |
|||
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ |
|||
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */ |
|||
.highlight .sx { color: #e6db74 } /* Literal.String.Other */ |
|||
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */ |
|||
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */ |
|||
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ |
|||
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ |
|||
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ |
|||
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ |
|||
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ |
|||
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ |
@ -0,0 +1,356 @@ |
|||
@import url(https://fonts.googleapis.com/css?family=Lato:300italic,700italic,300,700); |
|||
html { |
|||
background: #6C7989; |
|||
background: #6c7989 -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #6c7989), color-stop(100%, #434b55)) fixed; |
|||
background: #6c7989 -webkit-linear-gradient(#6c7989, #434b55) fixed; |
|||
background: #6c7989 -moz-linear-gradient(#6c7989, #434b55) fixed; |
|||
background: #6c7989 -o-linear-gradient(#6c7989, #434b55) fixed; |
|||
background: #6c7989 -ms-linear-gradient(#6c7989, #434b55) fixed; |
|||
background: #6c7989 linear-gradient(#6c7989, #434b55) fixed; |
|||
} |
|||
|
|||
body { |
|||
padding: 50px 0; |
|||
margin: 0; |
|||
font: 14px/1.5 Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; |
|||
color: #555; |
|||
font-weight: 300; |
|||
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAeCAYAAABNChwpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTNXG14zYAAAAUdEVYdENyZWF0aW9uIFRpbWUAMy82LzEygrTcTAAAAFRJREFUSIljfPDggZRf5RIGGNjUHsNATz6jXmSL1Kb2GLiAX+USBnrymRgGGDCORgFmoNAXjEbBaBSMRsFoFIxGwWgUjEbBaBSMRsFoFIxGwWgUAABYNujumib3wAAAAABJRU5ErkJggg==') fixed; |
|||
} |
|||
|
|||
.wrapper { |
|||
width: 640px; |
|||
margin: 0 auto; |
|||
background: #DEDEDE; |
|||
-webkit-border-radius: 8px; |
|||
-moz-border-radius: 8px; |
|||
-ms-border-radius: 8px; |
|||
-o-border-radius: 8px; |
|||
border-radius: 8px; |
|||
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0 0 0 1px, rgba(0, 0, 0, 0.45) 0 3px 10px; |
|||
-moz-box-shadow: rgba(0, 0, 0, 0.2) 0 0 0 1px, rgba(0, 0, 0, 0.45) 0 3px 10px; |
|||
box-shadow: rgba(0, 0, 0, 0.2) 0 0 0 1px, rgba(0, 0, 0, 0.45) 0 3px 10px; |
|||
} |
|||
|
|||
header, section, footer { |
|||
display: block; |
|||
} |
|||
|
|||
a { |
|||
color: #069; |
|||
text-decoration: none; |
|||
} |
|||
|
|||
p { |
|||
margin: 0 0 20px; |
|||
padding: 0; |
|||
} |
|||
|
|||
strong { |
|||
color: #222; |
|||
font-weight: 700; |
|||
} |
|||
|
|||
header { |
|||
-webkit-border-radius: 8px 8px 0 0; |
|||
-moz-border-radius: 8px 8px 0 0; |
|||
-ms-border-radius: 8px 8px 0 0; |
|||
-o-border-radius: 8px 8px 0 0; |
|||
border-radius: 8px 8px 0 0; |
|||
background: #C6EAFA; |
|||
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ddfbfc), color-stop(100%, #c6eafa)); |
|||
background: -webkit-linear-gradient(#ddfbfc, #c6eafa); |
|||
background: -moz-linear-gradient(#ddfbfc, #c6eafa); |
|||
background: -o-linear-gradient(#ddfbfc, #c6eafa); |
|||
background: -ms-linear-gradient(#ddfbfc, #c6eafa); |
|||
background: linear-gradient(#ddfbfc, #c6eafa); |
|||
position: relative; |
|||
padding: 15px 20px; |
|||
border-bottom: 1px solid #B2D2E1; |
|||
} |
|||
header h1 { |
|||
margin: 0; |
|||
padding: 0; |
|||
font-size: 24px; |
|||
line-height: 1.2; |
|||
color: #069; |
|||
text-shadow: rgba(255, 255, 255, 0.9) 0 1px 0; |
|||
} |
|||
header.without-description h1 { |
|||
margin: 10px 0; |
|||
} |
|||
header p { |
|||
margin: 0; |
|||
color: #61778B; |
|||
width: 300px; |
|||
font-size: 13px; |
|||
} |
|||
header p.view { |
|||
display: none; |
|||
font-weight: 700; |
|||
text-shadow: rgba(255, 255, 255, 0.9) 0 1px 0; |
|||
-webkit-font-smoothing: antialiased; |
|||
} |
|||
header p.view a { |
|||
color: #06c; |
|||
} |
|||
header p.view small { |
|||
font-weight: 400; |
|||
} |
|||
header ul { |
|||
margin: 0; |
|||
padding: 0; |
|||
list-style: none; |
|||
position: absolute; |
|||
z-index: 1; |
|||
right: 20px; |
|||
top: 20px; |
|||
height: 38px; |
|||
padding: 1px 0; |
|||
background: #5198DF; |
|||
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #77b9fb), color-stop(100%, #3782cd)); |
|||
background: -webkit-linear-gradient(#77b9fb, #3782cd); |
|||
background: -moz-linear-gradient(#77b9fb, #3782cd); |
|||
background: -o-linear-gradient(#77b9fb, #3782cd); |
|||
background: -ms-linear-gradient(#77b9fb, #3782cd); |
|||
background: linear-gradient(#77b9fb, #3782cd); |
|||
border-radius: 5px; |
|||
-webkit-box-shadow: inset rgba(255, 255, 255, 0.45) 0 1px 0, inset rgba(0, 0, 0, 0.2) 0 -1px 0; |
|||
-moz-box-shadow: inset rgba(255, 255, 255, 0.45) 0 1px 0, inset rgba(0, 0, 0, 0.2) 0 -1px 0; |
|||
box-shadow: inset rgba(255, 255, 255, 0.45) 0 1px 0, inset rgba(0, 0, 0, 0.2) 0 -1px 0; |
|||
width: auto; |
|||
} |
|||
header ul:before { |
|||
content: ''; |
|||
position: absolute; |
|||
z-index: -1; |
|||
left: -5px; |
|||
top: -4px; |
|||
right: -5px; |
|||
bottom: -6px; |
|||
background: rgba(0, 0, 0, 0.1); |
|||
-webkit-border-radius: 8px; |
|||
-moz-border-radius: 8px; |
|||
-ms-border-radius: 8px; |
|||
-o-border-radius: 8px; |
|||
border-radius: 8px; |
|||
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0 -1px 0, inset rgba(255, 255, 255, 0.7) 0 -1px 0; |
|||
-moz-box-shadow: rgba(0, 0, 0, 0.2) 0 -1px 0, inset rgba(255, 255, 255, 0.7) 0 -1px 0; |
|||
box-shadow: rgba(0, 0, 0, 0.2) 0 -1px 0, inset rgba(255, 255, 255, 0.7) 0 -1px 0; |
|||
} |
|||
header ul li { |
|||
width: 79px; |
|||
float: left; |
|||
border-right: 1px solid #3A7CBE; |
|||
height: 38px; |
|||
} |
|||
header ul li.single { |
|||
border: none; |
|||
} |
|||
header ul li + li { |
|||
width: 78px; |
|||
border-left: 1px solid #8BBEF3; |
|||
} |
|||
header ul li + li + li { |
|||
border-right: none; |
|||
width: 79px; |
|||
} |
|||
header ul a { |
|||
line-height: 1; |
|||
font-size: 11px; |
|||
color: #fff; |
|||
color: rgba(255, 255, 255, 0.8); |
|||
display: block; |
|||
text-align: center; |
|||
font-weight: 400; |
|||
padding-top: 6px; |
|||
height: 40px; |
|||
text-shadow: rgba(0, 0, 0, 0.4) 0 -1px 0; |
|||
} |
|||
header ul a strong { |
|||
font-size: 14px; |
|||
display: block; |
|||
color: #fff; |
|||
-webkit-font-smoothing: antialiased; |
|||
} |
|||
|
|||
section { |
|||
padding: 15px 20px; |
|||
font-size: 15px; |
|||
border-top: 1px solid #fff; |
|||
background: -webkit-gradient(linear, 50% 0%, 50% 700, color-stop(0%, #fafafa), color-stop(100%, #dedede)); |
|||
background: -webkit-linear-gradient(#fafafa, #dedede 700px); |
|||
background: -moz-linear-gradient(#fafafa, #dedede 700px); |
|||
background: -o-linear-gradient(#fafafa, #dedede 700px); |
|||
background: -ms-linear-gradient(#fafafa, #dedede 700px); |
|||
background: linear-gradient(#fafafa, #dedede 700px); |
|||
-webkit-border-radius: 0 0 8px 8px; |
|||
-moz-border-radius: 0 0 8px 8px; |
|||
-ms-border-radius: 0 0 8px 8px; |
|||
-o-border-radius: 0 0 8px 8px; |
|||
border-radius: 0 0 8px 8px; |
|||
position: relative; |
|||
} |
|||
|
|||
h1, h2, h3, h4, h5, h6 { |
|||
color: #222; |
|||
padding: 0; |
|||
margin: 0 0 20px; |
|||
line-height: 1.2; |
|||
} |
|||
|
|||
p, ul, ol, table, pre, dl { |
|||
margin: 0 0 20px; |
|||
} |
|||
|
|||
h1, h2, h3 { |
|||
line-height: 1.1; |
|||
} |
|||
|
|||
h1 { |
|||
font-size: 28px; |
|||
} |
|||
|
|||
h2 { |
|||
color: #393939; |
|||
} |
|||
|
|||
h3, h4, h5, h6 { |
|||
color: #494949; |
|||
} |
|||
|
|||
blockquote { |
|||
margin: 0 -20px 20px; |
|||
padding: 15px 20px 1px 40px; |
|||
font-style: italic; |
|||
background: #ccc; |
|||
background: rgba(0, 0, 0, 0.06); |
|||
color: #222; |
|||
} |
|||
|
|||
img { |
|||
max-width: 100%; |
|||
} |
|||
|
|||
code, pre { |
|||
font-family: Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal; |
|||
color: #333; |
|||
font-size: 12px; |
|||
overflow-x: auto; |
|||
} |
|||
|
|||
pre { |
|||
padding: 20px; |
|||
background: #3A3C42; |
|||
color: #f8f8f2; |
|||
margin: 0 -20px 20px; |
|||
} |
|||
pre code { |
|||
color: #f8f8f2; |
|||
} |
|||
li pre { |
|||
margin-left: -60px; |
|||
padding-left: 60px; |
|||
} |
|||
|
|||
table { |
|||
width: 100%; |
|||
border-collapse: collapse; |
|||
} |
|||
|
|||
th, td { |
|||
text-align: left; |
|||
padding: 5px 10px; |
|||
border-bottom: 1px solid #aaa; |
|||
} |
|||
|
|||
dt { |
|||
color: #222; |
|||
font-weight: 700; |
|||
} |
|||
|
|||
th { |
|||
color: #222; |
|||
} |
|||
|
|||
small { |
|||
font-size: 11px; |
|||
} |
|||
|
|||
hr { |
|||
border: 0; |
|||
background: #aaa; |
|||
height: 1px; |
|||
margin: 0 0 20px; |
|||
} |
|||
|
|||
footer { |
|||
width: 640px; |
|||
margin: 0 auto; |
|||
padding: 20px 0 0; |
|||
color: #ccc; |
|||
overflow: hidden; |
|||
} |
|||
footer a { |
|||
color: #fff; |
|||
font-weight: bold; |
|||
} |
|||
footer p { |
|||
float: left; |
|||
} |
|||
footer p + p { |
|||
float: right; |
|||
} |
|||
|
|||
@media print, screen and (max-width: 740px) { |
|||
body { |
|||
padding: 0; |
|||
} |
|||
|
|||
.wrapper { |
|||
-webkit-border-radius: 0; |
|||
-moz-border-radius: 0; |
|||
-ms-border-radius: 0; |
|||
-o-border-radius: 0; |
|||
border-radius: 0; |
|||
-webkit-box-shadow: none; |
|||
-moz-box-shadow: none; |
|||
box-shadow: none; |
|||
width: 100%; |
|||
} |
|||
|
|||
footer { |
|||
-webkit-border-radius: 0; |
|||
-moz-border-radius: 0; |
|||
-ms-border-radius: 0; |
|||
-o-border-radius: 0; |
|||
border-radius: 0; |
|||
padding: 20px; |
|||
width: auto; |
|||
} |
|||
footer p { |
|||
float: none; |
|||
margin: 0; |
|||
} |
|||
footer p + p { |
|||
float: none; |
|||
} |
|||
} |
|||
@media print, screen and (max-width:580px) { |
|||
header ul { |
|||
display: none; |
|||
} |
|||
|
|||
header p.view { |
|||
display: block; |
|||
} |
|||
|
|||
header p { |
|||
width: 100%; |
|||
} |
|||
} |
|||
@media print { |
|||
header p.view a small:before { |
|||
content: 'at http://github.com/'; |
|||
} |
|||
} |
@ -1,4 +0,0 @@ |
|||
library(testthat) |
|||
library(ggplot2) |
|||
|
|||
test_check("statebins") |
@ -1,34 +0,0 @@ |
|||
context("basic functionality") |
|||
test_that("we can do something", { |
|||
|
|||
require(ggplot2) |
|||
require(statebins) |
|||
|
|||
data(USArrests) |
|||
|
|||
USArrests$state <- rownames(USArrests) |
|||
|
|||
a1 <- USArrests |
|||
a2 <- USArrests |
|||
a3 <- USArrests |
|||
|
|||
a1$f <- 1 |
|||
a2$f <- 2 |
|||
a3$f <- 3 |
|||
|
|||
a4 <- rbind.data.frame(rbind.data.frame(a1, a2), a3) |
|||
|
|||
ggplot(a4, aes(state=state, fill=Assault)) + |
|||
geom_statebins() + |
|||
coord_equal() + |
|||
ggplot2::facet_wrap(~f) -> gg |
|||
|
|||
gb <- ggplot_build(gg) |
|||
|
|||
expect_equal(length(gb$plot$facet), 3) |
|||
|
|||
statebins(USArrests, value_col="Assault", name = "Assault") -> gg |
|||
|
|||
gb <- ggplot_build(gg) |
|||
|
|||
}) |