{"id":16571525,"url":"https://github.com/hrbrmstr/statebins","last_synced_at":"2025-10-05T20:54:33.484Z","repository":{"id":20067068,"uuid":"23335828","full_name":"hrbrmstr/statebins","owner":"hrbrmstr","description":"Alternative to choropleths of US States ala http://bit.ly/statebins","archived":false,"fork":false,"pushed_at":"2022-04-18T13:45:22.000Z","size":7890,"stargazers_count":123,"open_issues_count":10,"forks_count":27,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-07-16T02:35:05.637Z","etag":null,"topics":["cartogram","choropleth","choropleth-map","data-visualization","datavisualization","r","rstats","statebins"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hrbrmstr.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"patreon":"hrbrmstr"}},"created_at":"2014-08-26T02:21:39.000Z","updated_at":"2025-03-26T22:47:12.000Z","dependencies_parsed_at":"2022-08-23T15:31:13.880Z","dependency_job_id":null,"html_url":"https://github.com/hrbrmstr/statebins","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/hrbrmstr/statebins","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fstatebins","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fstatebins/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fstatebins/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fstatebins/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hrbrmstr","download_url":"https://codeload.github.com/hrbrmstr/statebins/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fstatebins/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278518905,"owners_count":26000177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cartogram","choropleth","choropleth-map","data-visualization","datavisualization","r","rstats","statebins"],"created_at":"2024-10-11T21:24:20.066Z","updated_at":"2025-10-05T20:54:33.467Z","avatar_url":"https://github.com/hrbrmstr.png","language":"R","readme":"---\noutput: rmarkdown::github_document\neditor_options: \n  chunk_output_type: console\n---\n\n```{r pkg-knitr-opts, include=FALSE}\nhrbrpkghelpr::global_opts()\n```\n\n```{r badges, results='asis', echo=FALSE, cache=FALSE}\nhrbrpkghelpr::stinking_badges()\n```\n\n```{r description, results='asis', echo=FALSE, cache=FALSE}\nhrbrpkghelpr::yank_title_and_description()\n```\n\n## What's Inside The Tin\n\nThe following functions are implemented/datasets included:\n\n```{r ingredients, results='asis', echo=FALSE, cache=FALSE}\nhrbrpkghelpr::describe_ingredients()\n```\n \n- `statebins`: (the original sole function in the package) Create a new ggplot-based \"statebin\" chart for USA states/territories\n\n## Installation\n\n```{r install-ex, results='asis', echo=FALSE, cache=FALSE}\nhrbrpkghelpr::install_block()\n```\n\n## Usage\n\nAll 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).\n\n```{r setup}\nlibrary(statebins)\nlibrary(cdcfluview)\nlibrary(hrbrthemes)\nlibrary(tidyverse)\n\n# current verison\npackageVersion(\"statebins\")\n```\n\n### The original wapo data\n\n```{r original}\nadat \u003c- read_csv(system.file(\"extdata\", \"wapostates.csv\", package=\"statebins\"))\n\nmutate(\n  adat, \n  share = cut(avgshare94_00, breaks = 4, labels = c(\"0-1\", \"1-2\", \"2-3\", \"3-4\"))\n) %\u003e% \n  statebins(\n    value_col = \"share\", \n    ggplot2_scale_function = scale_fill_brewer,\n    name = \"Share of workforce with jobs lost or threatened by trade\"\n  ) +\n  labs(title = \"1994-2000\") +\n  theme_statebins()\n```\n\n### Continuous scale, legend on top\n\n```{r continuous}\nstatebins(\n  adat, \n  value_col = \"avgshare01_07\",\n  name = \"Share of workforce with jobs lost or threatened by trade\",\n  palette = \"OrRd\", \n  direction = 1\n) +\n  labs(x=\"2001-2007\") + \n  theme_statebins(legend_position=\"top\")\n```\n\n### Continuous scale, no legend\n\n```{r continuous_noleg}\nstatebins(adat, value_col = \"avgshare08_12\", palette = \"Purples\") +\n  labs(x=\"2008-2010\") +\n  theme_statebins(legend_position = \"none\") \n```\n\n### Mortality data (has Puerto Rico)\n\n```{r mort}\n# from: http://www.cdc.gov/nchs/fastats/state-and-territorial-data.htm\n\ndat \u003c- read_csv(system.file(\"extdata\", \"deaths.csv\", package=\"statebins\"))\n\nstatebins(dat, value_col = \"death_rate\", name=\"Per 100K pop\") +\n  labs(title=\"Mortality Rate (2010)\") +\n  theme_statebins()\n```\n\n### Fertility data\n\n```{r fert}\nstatebins(dat, value_col=\"fertility_rate\", name=\"Per 100K pop\", palette=\"PuBuGn\") +\n  labs(title=\"Fertility Rate (2010)\") +\n  theme_statebins()\n```\n\n### Manual - perhaps good for elections?\n\n```{r manual}\nelection_2012 \u003c- suppressMessages(read_csv(system.file(\"extdata\", \"election2012.csv\", package=\"statebins\")))\n\nmutate(election_2012, value = ifelse(is.na(Obama), \"Romney\", \"Obama\")) %\u003e% \n  statebins(\n    font_size=4, dark_label = \"white\", light_label = \"white\",\n    ggplot2_scale_function = scale_fill_manual,\n    name = \"Winner\",\n    values = c(Romney = \"#2166ac\", Obama = \"#b2182b\")\n  ) +\n  theme_statebins()\n```\n\n### Rounded rects!\n\nYou can pass in a `grid::units()` call for the `radius` parameter.\n\nSlight curves:\n\n```{r rounded}\ndata(USArrests)\n\nUSArrests$state \u003c- rownames(USArrests)\nstatebins(USArrests, value_col=\"Assault\", name = \"Assault\", round=TRUE) +\n  theme_statebins(legend_position=\"right\")\n```\n\nCircles!\n\n```{r rounded2} \nstatebins(USArrests, value_col=\"Assault\", name = \"Assault\", round=TRUE, \n          radius=grid::unit(16, \"pt\"), palette=\"Reds\", direction=1) +\n  theme_statebins(legend_position=\"right\")\n```\n\n### Geom\n\n```{r sb_facet, fig.width=20, fig.height=15}\nflu \u003c- ili_weekly_activity_indicators(2017)\n\nggplot(flu, aes(state=statename, fill=activity_level)) +\n  geom_statebins() +\n  coord_equal() +\n  viridis::scale_fill_viridis(\n    name = \"ILI Activity Level  \", limits=c(0,10), breaks=0:10, option = \"magma\", direction = -1\n  ) +\n  facet_wrap(~weekend) +\n  labs(title=\"2017-18 Flu Season ILI Activity Level\") +\n  theme_statebins(base_family = font_ps) +\n  theme(plot.title=element_text(size=16, hjust=0)) +\n  theme(plot.margin = margin(30,30,30,30))\n```\n\n### All the \"states\"\n\n`statebins` now has PR, VI \u0026 NYC (by name or abbreviation) so you can use them, too:\n\n```{r all}\nlibrary(statebins)\nlibrary(tidyverse)\nlibrary(viridis)\n\ndata(USArrests)\n\n# make up some data for the example\n\nrownames_to_column(USArrests, \"state\") %\u003e%\n  bind_rows(\n    data_frame(\n      state = c(\"Virgin Islands\", \"Puerto Rico\", \"New York City\"),\n      Murder = rep(mean(max(USArrests$Murder),3)),\n      Assault = rep(mean(max(USArrests$Assault),3)),\n      Rape = rep(mean(max(USArrests$Rape),3)),\n      UrbanPop = c(93, 95, 100)\n    )\n  ) -\u003e us_arrests\n\nstatebins(us_arrests, value_col=\"Assault\",\n          ggplot2_scale_function = viridis::scale_fill_viridis) +\n  labs(title=\"USArrests + made up data\") +\n  theme_statebins(\"right\")\n```\n","funding_links":["https://patreon.com/hrbrmstr"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fstatebins","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhrbrmstr%2Fstatebins","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fstatebins/lists"}