Browse Source

Updated Figures

master
Bob Rudis 10 years ago
parent
commit
8c20f82e6f
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 10
      R/statebins.R
  2. 75
      _README.md

10
R/statebins.R

@ -6,6 +6,7 @@
#' @param state_col
#' @param value_col
#' @param text_color
#' @param font_size
#' @param state_border_col
#' @param breaks
#' @param labels
@ -17,7 +18,7 @@
#' @return ggplot2 object or grob
#' @export
statebins <- function(state_data, state_col="state", value_col="value",
text_color="white",
text_color="white", font_size=2,
state_border_col="white", breaks=5, labels=1:4,
legend_title="Legend", legend_position="top",
brewer_pal="PuBu", plot_title="", title_position="bottom") {
@ -42,7 +43,7 @@ statebins <- function(state_data, state_col="state", value_col="value",
gg <- ggplot(st.dat, aes(x=col, y=row, label=abbrev))
gg <- gg + geom_tile(aes(fill=fill_color))
gg <- gg + geom_tile(color=state_border_col, aes(fill=fill_color), size=3, show_guide=FALSE)
gg <- gg + geom_text(color=text_color, size=2)
gg <- gg + geom_text(color=text_color, size=font_size)
gg <- gg + scale_y_reverse()
gg <- gg + scale_fill_brewer(palette=brewer_pal, name=legend_title)
gg <- gg + coord_equal()
@ -80,6 +81,7 @@ statebins <- function(state_data, state_col="state", value_col="value",
#' @param state_col
#' @param value_col
#' @param text_color
#' @param font_size
#' @param state_border_col
#' @param legend_title
#' @param legend_position
@ -89,7 +91,7 @@ statebins <- function(state_data, state_col="state", value_col="value",
#' @return ggplot2 object or grob
#' @export
statebins_continuous <- function(state_data, state_col="state", value_col="value",
text_color="white",
text_color="white", font_size=2,
state_border_col="white",
legend_title="Legend", legend_position="top",
brewer_pal="PuBu", plot_title="", title_position="bottom") {
@ -112,7 +114,7 @@ statebins_continuous <- function(state_data, state_col="state", value_col="value
gg <- gg + geom_tile(aes_string(fill=value_col))
gg <- gg + geom_tile(color=state_border_col,
aes_string(fill=value_col), size=3, show_guide=FALSE)
gg <- gg + geom_text(color=text_color, size=2)
gg <- gg + geom_text(color=text_color, size=font_size)
gg <- gg + scale_y_reverse()
gg <- gg + continuous_scale("fill", "distiller",
gradient_n_pal(brewer_pal(type, brewer_pal)(6), NULL, "Lab"), na.value = "grey50", name=legend_title)

75
_README.md

@ -0,0 +1,75 @@
statesquares is ...
The following functions are implemented:
- `statebins` -
### News
- Version `1.0.0` released
### Installation
``` {.r}
devtools::install_github("hrbrmstr/statebins")
```
### Usage
``` {.r}
library(statebins)
```
## Loading required package: ggplot2
## Loading required package: grid
## Loading required package: scales
## Loading required package: gridExtra
``` {.r}
# current verison
packageVersion("statebins")
```
## [1] '1.0'
``` {.r}
dat <- read.csv("http://www.washingtonpost.com/wp-srv/special/business/states-most-threatened-by-trade/states.csv?cache=1", stringsAsFactors=FALSE)
gg <- statebins(dat, "state", "avgshare94_00", breaks=4,
labels=c("0-1", "1-2", "2-3", "3-4"),
legend_title="State Groups",
brewer_pal="Blues", text_color="black",
plot_title="1994-2000", title_position="bottom")
gg
```
![plot of chunk unnamed-chunk-3](./_README_files/figure-markdown_github/unnamed-chunk-31.png)
``` {.r}
gg2 <- statebins_continuous(dat, "state", "avgshare01_07",
legend_title="States", legend_position="none",
brewer_pal="OrRd", text_color="black",
plot_title="1994-2000", title_position="bottom")
gg2
```
![plot of chunk unnamed-chunk-3](./_README_files/figure-markdown_github/unnamed-chunk-32.png)
### Test Results
``` {.r}
library(statebins)
library(testthat)
date()
```
## [1] "Mon Aug 25 22:27:38 2014"
``` {.r}
test_dir("tests/")
```
## basic functionality :
Loading…
Cancel
Save