Type: | Package |
Title: | Create United States Uniform Cartogram Heatmaps |
Version: | 1.4.0 |
Date: | 2020-07-08 |
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: | viridis, RColorBrewer, covr, tinytest |
Depends: | R (≥ 3.5.0), |
Imports: | ggplot2 (≥ 2.2.1), scales (≥ 0.5.0), grid |
RoxygenNote: | 7.1.1 |
Collate: | 'aaa.R' 'geom-rrect.r' 'geom-rtile.R' 'geom-statebins.r' 'gutil.R' 'statebins-package.R' 'statebins.R' 'theme-statebin.R' 'util.R' |
NeedsCompilation: | no |
Packaged: | 2020-07-08 17:40:11 UTC; hrbrmstr |
Author: | Bob Rudis |
Repository: | CRAN |
Date/Publication: | 2020-07-08 23:00:02 UTC |
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.
Author(s)
Bob Rudis (bob@rud.is)
A statebins Geom
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.
There are two special/critical aes()
mappings:
-
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)
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
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
border_col |
border color of the state squares, default " |
border_size |
thickness of the square state borders |
lbl_size |
font size (relative) of the label text |
dark_lbl , light_lbl |
colrs to be uses when the label should be dark or light. The function automagically computes when this should be. |
radius |
the corner radius |
... |
other arguments passed on to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Format
An object of class GeomStatebins
(inherits from Geom
, ggproto
, gg
) of length 7.
Examples
## Not run:
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))
## End(Not run)
"State" abbreviation to name data frame
Description
"State" abbreviation to name data frame
Create a new ggplot-based "statebin" chart for USA states/territories
Description
Pass in a data frame and get back a square choropleth.
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
state_data |
data frame of states and values to plot |
state_col |
column name in |
value_col |
column name in |
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. |
font_size |
font size (default = |
state_border_col |
default " |
state_border_size |
border size |
round |
rounded corners (default: |
radius |
if |
ggplot2_scale_function |
ggplot2 scale function to use. Defaults to |
... |
additional parameters to the scale function |
Details
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.
Value
ggplot2 object
Examples
data(USArrests)
USArrests$state <- rownames(USArrests)
statebins(USArrests, value_col="Assault", name = "Assault") +
theme_statebins(legend_position="right")
Base statebins theme
Description
Clears out most of the cruft. Builds off of theme_bw()
Usage
theme_statebins(legend_position = "bottom", base_size = 11, base_family = "")
Arguments
legend_position |
fills in |
base_family , base_size |
same as |