• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    R
  • License
    Other
  • Created over 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Alternative to choropleths of US States ala http://bit.ly/statebins

Project Status: Active โ€“ The project has reached a stable, usable state and is being actively developed. Signed by Signed commit % Linux build Status Windows build status Coverage Status cran checks CRAN status Minimal R Version License

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

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 installed.

Usage

All of the following examples use the WaPo data. 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).

library(statebins)
library(cdcfluview)
library(hrbrthemes)
library(tidyverse)

# current verison
packageVersion("statebins")
## [1] '1.4.0'

The original wapo data

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

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

statebins(adat, value_col = "avgshare08_12", palette = "Purples") +
  labs(x="2008-2010") +
  theme_statebins(legend_position = "none") 

Mortality data (has Puerto Rico)

# 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

statebins(dat, value_col="fertility_rate", name="Per 100K pop", palette="PuBuGn") +
  labs(title="Fertility Rate (2010)") +
  theme_statebins()

Manual - perhaps good for elections?

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:

data(USArrests)

USArrests$state <- rownames(USArrests)
statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE) +
  theme_statebins(legend_position="right")

Circles!

statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE, 
          radius=grid::unit(16, "pt"), palette="Reds", direction=1) +
  theme_statebins(legend_position="right")

Geom

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:

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")

More Repositories

1

hrbrthemes

๐Ÿ” Opinionated, typographic-centric ggplot2 themes and theme components
R
1,139
star
2

pewpew

โญ โญ โญ Build your own IP Attack Maps with SOUND!
JavaScript
1,011
star
3

waffle

๐Ÿ Make waffle (square pie) charts in R
R
747
star
4

ggalt

๐ŸŒŽ Extra Coordinate Systems, Geoms, Statistical Transformations & Scales for 'ggplot2'
R
641
star
5

markdowntemplates

โœ…๐Ÿ”ป A collection of alternate R markdown templates
CSS
318
star
6

docxtractr

โœ‚๏ธ Extract Tables from Microsoft Word Documents with R
R
169
star
7

vegalite

R ggplot2 "bindings" for Vega-Lite
JavaScript
158
star
8

ggchicklet

๐Ÿ€ซ Create Chicklet (Rounded Segmented Column) Charts
HTML
157
star
9

streamgraph

ใ€ฐ๏ธ htmlwidget for creating streamgraph visualizations in R
HTML
146
star
10

metricsgraphics

๐Ÿ“ˆ htmlwidget interface to the MetricsGraphics.js D3 chart library
HTML
133
star
11

sergeant

๐Ÿ’‚โ€โ™‚๏ธ Tools to Transform and Query Data with 'Apache' 'Drill'
R
126
star
12

splashr

๐Ÿ’ฆ Tools to Work with the 'Splash' JavaScript Rendering Service in R
R
99
star
13

RSwitch

๐ŸŽ› A small menubar app that allows you to switch between R versions quickly (if you have multiple versions of R framework installed).
Swift
99
star
14

newsflash

Tools to Work with the Internet Archive and GDELT Television Explorer in R
R
88
star
15

curlconverter

โžฐ โžก๏ธ โž– Translate cURL command lines into parameters for use with httr or actual httr calls (R)
R
88
star
16

darksky

โ˜๏ธ R interface to the Dark Sky API [APPLE IS SHUTTING DOWN THE API 2022-12-31]
R
82
star
17

freebase

๐Ÿ‘ƒ๐ŸฝA 'usethis'-like Package for Base R Pseudo-equivalents of 'tidyverse' Code
R
82
star
18

albersusa

Tools, shapefiles & data to work with an "AlbersUSA" composite projection in R
R
75
star
19

21-recipes

๐Ÿ“• An R/rtweet edition of Matthew A. Russell's Python Twitter Recipes Book
CSS
72
star
20

nominatim

๐ŸŒ Tools for Working with the 'Nominatim' API in R
R
71
star
21

hrbraddins

Additional Addins for RStudio
R
68
star
22

ggeconodist

๐Ÿ“‰ Create Diminutive Distribution Charts
R
67
star
23

decapitated

Headless 'Chrome' Orchestration in R
R
66
star
24

taucharts

๐Ÿ“Š An R htmlwidget interface to the TauCharts javascript library
HTML
65
star
25

speedtest

๐Ÿ“ Measure upload/download speed/bandwidth for your network with R
R
64
star
26

ggcounty

๐ŸŒ Generate ggplot2 geom_map county maps
R
62
star
27

pluralize

An R package to "Pluralize and Singularize Any Word"
JavaScript
60
star
28

qrencoder

๐Ÿ”ณ Make QR codes in R via libqrencode
C
59
star
29

quarto-organization-template

A Quarto RevealJS Organization Boilerplate Template You Can Clone And Modify Quickly
SCSS
59
star
30

swatches

๐ŸŽจ Read, Inspect, Manipulate, and Save (ASE-only for save) Color Swatch Files
R
56
star
31

cdcfluview

๐Ÿ˜ท R package to Retrieve U.S. Flu Season Data from the CDC FluView Portal (WHO & ILINet)
R
56
star
32

rgeocodio

Tools to Work with the https://geocod.io/ API
R
56
star
33

cloc

๐Ÿ”ข R package to the perl cloc script (which counts blank lines, comment lines, and physical lines of source code in source files/trees/archives)
Perl
55
star
34

dtupdate

The dtupdate package has functions that try to make it easier to keep up with the non-CRAN universe
R
55
star
35

wayback

โช Tools to Work with the Various Internet Archive Wayback Machine APIs
R
54
star
36

orangetext

๐ŸŠ๐Ÿ“„ : An #rstats project to keep track of The ๐ŸŠ One's speeches
R
53
star
37

rstudioconf2017

Slides/code/data from rstudio:: conf 2017
ASP
52
star
38

ndjson

โ™จ๏ธ Wicked-Fast Streaming 'JSON' ('ndjson') Reader in R
C++
51
star
39

ggvis-maps

Examples of various kinds of maps in ggvis (with & without shiny)
R
51
star
40

iptools

๐Ÿด A toolkit for manipulating, validating and testing IP addresses and ranges, along with datasets relating to IP addresses. While it primarily has support for the IPv4 address space, more extensive IPv6 support is intended.
Scilab
51
star
41

tidyweb

Easily Install and Load Modern Web-Scraping Packages
R
50
star
42

weatherkit

๐ŸŽ๐ŸŒก๐Ÿ”Ž Obtain Historical, Current, and Predictive Weather Data from Apple WeatherKit REST API in R
R
46
star
43

pdfbox

๐Ÿ“„โ—ป๏ธ Create, Maniuplate and Extract Data from PDF Files (R Apache PDFBox wrapper)
Java
46
star
44

xmlview

๐Ÿ“ƒ Format, Query and Pretty Print 'HTML'/'XML' Content in R (RStudio viewer or browser)
JavaScript
46
star
45

msgxtractr

๐Ÿ“‡ Extract contents from Outlook '.msg' files in R
C
44
star
46

worldtilegrid

๐Ÿ”ฒ๐Ÿ—บ World Tile Grid Geom for ggplot2 [WIP]
R
43
star
47

QuickLookR

macOS QuickLook plugin for R save(), saveRDS() & feather files
C
42
star
48

voteogram

U.S. House and Senate Voting Cartogram Generators in R
R
41
star
49

nifffty

Small R package to post events to IFTTT Maker channel/recipes
R
40
star
50

githubdashboard

#rstats github flexdashboard
HTML
40
star
51

overpass

โ„น๏ธ Tools to Work With the OpenStreetMap (OSM) Overpass API in R
HTML
40
star
52

hrbragg

Typography-centric Themes, Theme Components, and Utilities for 'ggplot2' and 'ragg'.
R
39
star
53

netintel

A collection of "network intelligence" utilities for R. ASN info, IP reputation, etc.
R
39
star
54

htmlunit

๐Ÿ•ธ๐Ÿงฐโ˜•๏ธTools to Scrape Dynamic Web Content via the 'HtmlUnit' Java Library
R
38
star
55

Rforecastio

โ˜๏ธ Simple R interface to forecast.io weather data
R
38
star
56

omdbapi

R package to access the OMDB API (http://www.omdbapi.com/)
R
38
star
57

mactheknife

๐Ÿฆˆ Various โ€˜macOSโ€™-oriented Tools and Utilities in R
R
37
star
58

tdigest

Wicked Fast, Accurate Quantiles Using 't-Digests'
C
36
star
59

hrbrmisc

personal R pkg
R
35
star
60

webr-experiments

๐Ÿ•ธ๏ธ ๐Ÿงช hrbrmstr's WebR Experiments
HTML
34
star
61

2017-year-in-review

Year in Review with R Rmd Template
34
star
62

crafter

๐Ÿ”ฌ An R package to work with PCAPs
R
33
star
63

longurl

โ„น๏ธ Small R package for no-API-required URL expansion
R
32
star
64

greywatch

๐Ÿ•ต๐Ÿฝ macOS Big Sur desktop app to monitor active TCP connections through the lens of GreyNoise
Swift
32
star
65

ipv4-heatmap

Update to The Measurement Factory ipv4-heatmap codebase
C
32
star
66

jsonview

JSON pretty printer & viewer in R
JavaScript
30
star
67

rpwnd

๐Ÿ™… The Most Benignly Malicious R Package on the Internet
R
30
star
68

statically

๐Ÿ“ธ Generate Webpage Screenshots Using the Statically API
R
28
star
69

rradar

๐ŸŒŠ Animate current U.S. NOAA NWS N0R Radar Images
R
27
star
70

archinfo

๐–ผ† Returns a list of running processes and the architecture (x86_64/arm64) they are running under.
C
26
star
71

ohq2quarto

Save an Observable HQ Notebook to a Quarto project
Rust
25
star
72

osqueryr

โ‡ 'osquery' 'DBI' and 'dbplyr' Interface for R
R
25
star
73

ulid

โš™๏ธ Universally Unique Lexicographically Sortable Identifiers in R
C++
25
star
74

webr-monaco-repl

๐Ÿงช ๐Ÿ•ธ๏ธ Monaco-powered WebR "REPL"
JavaScript
24
star
75

imprint

Create Customized 'ggplot2' and 'R Markdown' Themes for Your Organization
R
24
star
76

gdns

Tools to work with the Google DNS over HTTPS API in R
R
24
star
77

2020-george-floyd-protests

Code to collect data from various sources on the 2020 George Floyd protests.
HTML
23
star
78

fileio

โณ Ephemeral File, Text or R Data Sharing with 'file.io'
R
23
star
79

widgetcard

Tools to Enable Easier Content Embedding in Tweets
R
23
star
80

attckr

โš”๏ธMITRE ATT&CK Machinations in R
R
23
star
81

mgrs

๐ŸŒ An R Package to Convert 'MGRS' (Military Grid Reference System) References From/To Other Coordiante Systems
C
23
star
82

webr-app

๐Ÿงช ๐Ÿ•ธ๏ธ A Way Better Structured WebR Demo App
JavaScript
23
star
83

pubcrawl

๐Ÿบ๐Ÿ“– Convert 'epub' Files to Text (Use https://github.com/ropensci/epubr instead)
R
22
star
84

xslt

lightweight XSLT processing package for R based on xmlwrapp
R
22
star
85

swiftr

Seamless R and Swift Integration
R
22
star
86

ggsolar

๐Ÿช Generate "solar system" plots with {ggplot2}
R
22
star
87

facetedcountryheatmaps

Small sample Rmd to show how to make faceted country heatmaps in a couple different ways in R
HTML
22
star
88

ipapi

An R package to geolocate IPv4/6 addresses and/or domain names using ip-api.com's API
HTML
22
star
89

firasans

๐Ÿ” Fira Sans Condensed + Fira Mono Font Theme Based on hrbrthemes
R
22
star
90

drill-sergeant-rstats

๐Ÿ“— A Little Book About Using Apache Drill and R
R
22
star
91

slopegraph

A 'slopegraph' ('table-chart') generator in Python using Cairo/Raphaรซl. Currently handles a two column chart with _many_ output options. Look at the '/examples' directory for sample configurations, data files and output formats.
JavaScript
22
star
92

reveal-qmd

Chrome Extension To Reveal Observable Notebooks As Quarto QMD {ojs} Blocks & provide downloads of FileAttachments and zipped Quarto project
JavaScript
21
star
93

elpresidente

๐Ÿ‡บ๐Ÿ‡ธ Search and Extract Corpus Elements from 'The American Presidency Project'
R
21
star
94

wand

Use 'magic' to guess file types
R
21
star
95

warc

๐Ÿ“‡ Tools to Work with the Web Archive Ecosystem in R
R
21
star
96

rstudio-electron-quarto-installer

Download and install the latest macOS RStudio (electron) daily along with the latest Quarto pre-release
Shell
21
star
97

urlscan

๐Ÿ‘€ Analyze Websites and Resources They Request
R
21
star
98

wondr

Tools to Work with there CDC WONDER API in R
R
20
star
99

supercaliheatmapwidget

๐Ÿ“… Supercalifragilistic HTML Calendar Heatmaps
JavaScript
20
star
100

secede-2014

R dplyr/tidyr/rvest/TopoJSON tutorial using the 2014 Scotland secession vote
R
20
star