Browse Source

rounded rects

master
boB Rudis 7 years ago
parent
commit
5808cc0cb3
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 35
      README.Rmd
  2. 39
      README.md
  3. 0
      README_files/figure-gfm/all-1.png
  4. 0
      README_files/figure-gfm/continuous-1.png
  5. 0
      README_files/figure-gfm/continuous_noleg-1.png
  6. 0
      README_files/figure-gfm/fert-1.png
  7. 0
      README_files/figure-gfm/manual-1.png
  8. 0
      README_files/figure-gfm/mort-1.png
  9. 0
      README_files/figure-gfm/original-1.png
  10. 0
      README_files/figure-gfm/rounded-1.png

35
README.Rmd

@ -3,7 +3,7 @@ output: rmarkdown::github_document
editor_options: editor_options:
chunk_output_type: console chunk_output_type: console
--- ---
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE, include=FALSE} ```{r ugh, echo=FALSE, message=FALSE, warning=FALSE, error=FALSE, include=FALSE}
knitr::opts_chunk$set(message=FALSE, warning=FALSE, fig.retina=2) knitr::opts_chunk$set(message=FALSE, warning=FALSE, fig.retina=2)
options(width=120) options(width=120)
``` ```
@ -21,7 +21,7 @@ The following functions are implemented:
## Installation ## Installation
```{r eval=FALSE} ```{r install, eval=FALSE}
devtools::install_github("hrbrmstr/statebins") devtools::install_github("hrbrmstr/statebins")
``` ```
@ -29,15 +29,17 @@ devtools::install_github("hrbrmstr/statebins")
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). 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} ```{r setup}
library(statebins) library(statebins)
library(tidyverse) library(tidyverse)
# current verison # current verison
packageVersion("statebins") packageVersion("statebins")
```
# the original wapo data ### The original wapo data
```{r original}
adat <- suppressMessages(read_csv(system.file("extdata", "wapostates.csv", package="statebins"))) adat <- suppressMessages(read_csv(system.file("extdata", "wapostates.csv", package="statebins")))
mutate( mutate(
@ -51,9 +53,11 @@ mutate(
) + ) +
labs(title = "1994-2000") + labs(title = "1994-2000") +
theme_statebins() theme_statebins()
```
# continuous scale, legend on top ### Continuous scale, legend on top
```{r continuous}
statebins( statebins(
adat, value_col = "avgshare01_07", adat, value_col = "avgshare01_07",
name = "Share of workforce with jobs lost or threatened by trade", name = "Share of workforce with jobs lost or threatened by trade",
@ -61,16 +65,19 @@ statebins(
) + ) +
labs(x="2001-2007") + labs(x="2001-2007") +
theme_statebins(legend_position="top") theme_statebins(legend_position="top")
```
### Continuous scale, no legend
# continuous scale, no legend ```{r continuous_noleg}
statebins(adat, value_col = "avgshare08_12", palette = "Purples") + statebins(adat, value_col = "avgshare08_12", palette = "Purples") +
labs(x="2008-2010") + labs(x="2008-2010") +
theme_statebins(legend_position = "none") theme_statebins(legend_position = "none")
```
### Mortality data (has Puerto Rico)
# mortality data (has Puerto Rico) ```{r mort}
# from: http://www.cdc.gov/nchs/fastats/state-and-territorial-data.htm # from: http://www.cdc.gov/nchs/fastats/state-and-territorial-data.htm
dat <- suppressMessages(read_csv(system.file("extdata", "deaths.csv", package="statebins"))) dat <- suppressMessages(read_csv(system.file("extdata", "deaths.csv", package="statebins")))
@ -78,15 +85,19 @@ dat <- suppressMessages(read_csv(system.file("extdata", "deaths.csv", package="s
statebins(dat, value_col = "death_rate", name="Per 100K pop") + statebins(dat, value_col = "death_rate", name="Per 100K pop") +
labs(title="Mortality Rate (2010)") + labs(title="Mortality Rate (2010)") +
theme_statebins() theme_statebins()
```
# fertility data ### Fertility data
```{r fert}
statebins(dat, value_col="fertility_rate", name="Per 100K pop", palette="PuBuGn") + statebins(dat, value_col="fertility_rate", name="Per 100K pop", palette="PuBuGn") +
labs(title="Fertility Rate (2010)") + labs(title="Fertility Rate (2010)") +
theme_statebins() theme_statebins()
```
# manual - perhaps good for elections? ### Manual - perhaps good for elections?
```{r manual}
election_2012 <- suppressMessages(read_csv(system.file("extdata", "election2012.csv", package="statebins"))) election_2012 <- suppressMessages(read_csv(system.file("extdata", "election2012.csv", package="statebins")))
mutate(election_2012, value = ifelse(is.na(Obama), "Romney", "Obama")) %>% mutate(election_2012, value = ifelse(is.na(Obama), "Romney", "Obama")) %>%
@ -101,7 +112,7 @@ mutate(election_2012, value = ifelse(is.na(Obama), "Romney", "Obama")) %>%
### Rounded rects! ### Rounded rects!
```{r} ```{r rounded}
data(USArrests) data(USArrests)
USArrests$state <- rownames(USArrests) USArrests$state <- rownames(USArrests)
@ -113,7 +124,7 @@ statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE) +
`statebins` now has PR, VI & NYC (by name or abbreviation) so you can use them, too: `statebins` now has PR, VI & NYC (by name or abbreviation) so you can use them, too:
```{r} ```{r all}
library(statebins) library(statebins)
library(tidyverse) library(tidyverse)
library(viridis) library(viridis)

39
README.md

@ -35,9 +35,9 @@ packageVersion("statebins")
## [1] '1.3.0' ## [1] '1.3.0'
``` r ### The original wapo data
# the original wapo data
``` r
adat <- suppressMessages(read_csv(system.file("extdata", "wapostates.csv", package="statebins"))) adat <- suppressMessages(read_csv(system.file("extdata", "wapostates.csv", package="statebins")))
mutate( mutate(
@ -53,11 +53,11 @@ mutate(
theme_statebins() theme_statebins()
``` ```
<img src="README_files/figure-gfm/unnamed-chunk-3-1.png" width="672" /> <img src="README_files/figure-gfm/original-1.png" width="672" />
``` r ### Continuous scale, legend on top
# continuous scale, legend on top
``` r
statebins( statebins(
adat, value_col = "avgshare01_07", adat, value_col = "avgshare01_07",
name = "Share of workforce with jobs lost or threatened by trade", name = "Share of workforce with jobs lost or threatened by trade",
@ -67,20 +67,21 @@ statebins(
theme_statebins(legend_position="top") theme_statebins(legend_position="top")
``` ```
<img src="README_files/figure-gfm/unnamed-chunk-3-2.png" width="672" /> <img src="README_files/figure-gfm/continuous-1.png" width="672" />
``` r ### Continuous scale, no legend
# continuous scale, no legend
``` r
statebins(adat, value_col = "avgshare08_12", palette = "Purples") + statebins(adat, value_col = "avgshare08_12", palette = "Purples") +
labs(x="2008-2010") + labs(x="2008-2010") +
theme_statebins(legend_position = "none") theme_statebins(legend_position = "none")
``` ```
<img src="README_files/figure-gfm/unnamed-chunk-3-3.png" width="672" /> <img src="README_files/figure-gfm/continuous_noleg-1.png" width="672" />
### Mortality data (has Puerto Rico)
``` r ``` r
# mortality data (has Puerto Rico)
# from: http://www.cdc.gov/nchs/fastats/state-and-territorial-data.htm # from: http://www.cdc.gov/nchs/fastats/state-and-territorial-data.htm
dat <- suppressMessages(read_csv(system.file("extdata", "deaths.csv", package="statebins"))) dat <- suppressMessages(read_csv(system.file("extdata", "deaths.csv", package="statebins")))
@ -90,21 +91,21 @@ statebins(dat, value_col = "death_rate", name="Per 100K pop") +
theme_statebins() theme_statebins()
``` ```
<img src="README_files/figure-gfm/unnamed-chunk-3-4.png" width="672" /> <img src="README_files/figure-gfm/mort-1.png" width="672" />
``` r ### Fertility data
# fertility data
``` r
statebins(dat, value_col="fertility_rate", name="Per 100K pop", palette="PuBuGn") + statebins(dat, value_col="fertility_rate", name="Per 100K pop", palette="PuBuGn") +
labs(title="Fertility Rate (2010)") + labs(title="Fertility Rate (2010)") +
theme_statebins() theme_statebins()
``` ```
<img src="README_files/figure-gfm/unnamed-chunk-3-5.png" width="672" /> <img src="README_files/figure-gfm/fert-1.png" width="672" />
``` r ### Manual - perhaps good for elections?
# manual - perhaps good for elections?
``` r
election_2012 <- suppressMessages(read_csv(system.file("extdata", "election2012.csv", package="statebins"))) election_2012 <- suppressMessages(read_csv(system.file("extdata", "election2012.csv", package="statebins")))
mutate(election_2012, value = ifelse(is.na(Obama), "Romney", "Obama")) %>% mutate(election_2012, value = ifelse(is.na(Obama), "Romney", "Obama")) %>%
@ -117,7 +118,7 @@ mutate(election_2012, value = ifelse(is.na(Obama), "Romney", "Obama")) %>%
theme_statebins() theme_statebins()
``` ```
<img src="README_files/figure-gfm/unnamed-chunk-3-6.png" width="672" /> <img src="README_files/figure-gfm/manual-1.png" width="672" />
### Rounded rects\! ### Rounded rects\!
@ -129,7 +130,7 @@ statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE) +
theme_statebins(legend_position="right") theme_statebins(legend_position="right")
``` ```
<img src="README_files/figure-gfm/unnamed-chunk-4-1.png" width="672" /> <img src="README_files/figure-gfm/rounded-1.png" width="672" />
### All the “states” ### All the “states”
@ -162,4 +163,4 @@ statebins(us_arrests, value_col="Assault",
theme_statebins("right") theme_statebins("right")
``` ```
<img src="README_files/figure-gfm/unnamed-chunk-5-1.png" width="672" /> <img src="README_files/figure-gfm/all-1.png" width="672" />

0
README_files/figure-gfm/unnamed-chunk-5-1.png → README_files/figure-gfm/all-1.png

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

0
README_files/figure-gfm/unnamed-chunk-3-2.png → README_files/figure-gfm/continuous-1.png

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 86 KiB

0
README_files/figure-gfm/unnamed-chunk-3-3.png → README_files/figure-gfm/continuous_noleg-1.png

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 73 KiB

0
README_files/figure-gfm/unnamed-chunk-3-5.png → README_files/figure-gfm/fert-1.png

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

0
README_files/figure-gfm/unnamed-chunk-3-6.png → README_files/figure-gfm/manual-1.png

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB

0
README_files/figure-gfm/unnamed-chunk-3-4.png → README_files/figure-gfm/mort-1.png

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 86 KiB

0
README_files/figure-gfm/unnamed-chunk-3-1.png → README_files/figure-gfm/original-1.png

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

0
README_files/figure-gfm/unnamed-chunk-4-1.png → README_files/figure-gfm/rounded-1.png

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 118 KiB

Loading…
Cancel
Save