• Stars
    star
    120
  • Rank 285,538 (Top 6 %)
  • Language
    R
  • License
    Other
  • Created over 9 years ago
  • Updated about 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
990
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
316
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

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
13

splashr

💦 Tools to Work with the 'Splash' JavaScript Rendering Service in R
R
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

xslt

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

swiftr

Seamless R and Swift Integration
R
22
star
85

ggsolar

🪐 Generate "solar system" plots with {ggplot2}
R
22
star
86

facetedcountryheatmaps

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

firasans

🔏 Fira Sans Condensed + Fira Mono Font Theme Based on hrbrthemes
R
22
star
88

pubcrawl

🍺📖 Convert 'epub' Files to Text (Use https://github.com/ropensci/epubr instead)
R
22
star
89

ipapi

An R package to geolocate IPv4/6 addresses and/or domain names using ip-api.com's API
HTML
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

warc

📇 Tools to Work with the Web Archive Ecosystem in R
R
21
star
95

wand

Use 'magic' to guess file types
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