Browse Source

Print NA states

master
Mathew Kiang 6 years ago
parent
commit
15f7a09c38
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 2
      DESCRIPTION
  2. 7
      R/statebins.R
  3. 9
      R/util.R
  4. 2
      man/geom_statebins.Rd
  5. 8
      man/statebins.Rd
  6. BIN
      tests/.DS_Store

2
DESCRIPTION

@ -36,7 +36,7 @@ Imports:
ggplot2 (>= 2.2.1), ggplot2 (>= 2.2.1),
scales (>= 0.5.0), scales (>= 0.5.0),
grid grid
RoxygenNote: 6.0.1 RoxygenNote: 6.0.1.9000
Collate: Collate:
'aaa.R' 'aaa.R'
'geom-rrect.r' 'geom-rrect.r'

7
R/statebins.R

@ -22,7 +22,7 @@
#' @param state_col column name in \code{state_data} that has the states. no duplicates #' @param state_col column name in \code{state_data} that has the states. no duplicates
#' and can be names (e.g. "\code{Maine}") or abbreviatons (e.g. "\code{ME}") #' and can be names (e.g. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")
#' @param value_col column name in \code{state_data} that holds the values to be plotted #' @param value_col column name in \code{state_data} that holds the values to be plotted
#' @param dark_label,light_label dark/light label colors. The specified color will be used #' @param dark_label,light_label,na_label dark/light/NA label colors. The specified color will be used
#' when the algorithm determines labels should be inverted. #' when the algorithm determines labels should be inverted.
#' @param font_size font size (default = \code{3}) #' @param font_size font size (default = \code{3})
#' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes #' @param state_border_col default "\code{white}" - this creates the "spaces" between boxes
@ -43,7 +43,8 @@
#' theme_statebins(legend_position="right") #' theme_statebins(legend_position="right")
statebins <- function(state_data, statebins <- function(state_data,
state_col="state", value_col="value", state_col="state", value_col="value",
dark_label = "black", light_label = "white", font_size=3, dark_label = "black", light_label = "white", na_label = "white",
font_size=3,
state_border_col="white", state_border_size=2, state_border_col="white", state_border_size=2,
round = FALSE, radius = grid::unit(6, "pt"), round = FALSE, radius = grid::unit(6, "pt"),
ggplot2_scale_function=ggplot2::scale_fill_distiller, ggplot2_scale_function=ggplot2::scale_fill_distiller,
@ -84,7 +85,7 @@ statebins <- function(state_data,
gg <- gg + geom_text(data = st.dat, gg <- gg + geom_text(data = st.dat,
aes_string(x = "col", y = "row", label = "abbrev"), aes_string(x = "col", y = "row", label = "abbrev"),
angle = 0, angle = 0,
color = .sb_invert(gb$data[[1]]$fill, dark_label, light_label), color = .sb_invert(gb$data[[1]]$fill, dark_label, light_label, na_label),
size = font_size) size = font_size)
gg gg

9
R/util.R

@ -1,4 +1,4 @@
.sb_invert <- function(hex_color, dark_color="black", light_color="white") { .sb_invert <- function(hex_color, dark_color="black", light_color="white", na_color = "white") {
hex_color <- gsub("#", "", hex_color) hex_color <- gsub("#", "", hex_color)
@ -8,7 +8,12 @@
YIQ <- ((R*299) + (G*587) + (B*114)) / 1000 YIQ <- ((R*299) + (G*587) + (B*114)) / 1000
return(ifelse(YIQ >= 128, dark_color, light_color)) return(
ifelse(is.na(YIQ), na_color,
ifelse(
YIQ >= 128, dark_color, light_color)
)
)
} }

2
man/geom_statebins.Rd

@ -5,7 +5,7 @@
\alias{geom_statebins} \alias{geom_statebins}
\alias{GeomStatebins} \alias{GeomStatebins}
\title{A statebins Geom} \title{A statebins Geom}
\format{An object of class \code{GeomStatebins} (inherits from \code{Geom}, \code{ggproto}, \code{gg}) of length 7.} \format{An object of class \code{GeomStatebins} (inherits from \code{Geom}, \code{ggproto}) of length 7.}
\usage{ \usage{
geom_statebins(mapping = NULL, data = NULL, border_col = "white", geom_statebins(mapping = NULL, data = NULL, border_col = "white",
border_size = 2, lbl_size = 3, dark_lbl = "black", border_size = 2, lbl_size = 3, dark_lbl = "black",

8
man/statebins.Rd

@ -5,9 +5,9 @@
\title{Create a new ggplot-based "statebin" chart for USA states/territories} \title{Create a new ggplot-based "statebin" chart for USA states/territories}
\usage{ \usage{
statebins(state_data, state_col = "state", value_col = "value", statebins(state_data, state_col = "state", value_col = "value",
dark_label = "black", light_label = "white", font_size = 3, dark_label = "black", light_label = "white", na_label = "white",
state_border_col = "white", state_border_size = 2, round = FALSE, font_size = 3, state_border_col = "white", state_border_size = 2,
radius = grid::unit(6, "pt"), round = FALSE, radius = grid::unit(6, "pt"),
ggplot2_scale_function = ggplot2::scale_fill_distiller, ...) ggplot2_scale_function = ggplot2::scale_fill_distiller, ...)
} }
\arguments{ \arguments{
@ -18,7 +18,7 @@ and can be names (e.g. "\code{Maine}") or abbreviatons (e.g. "\code{ME}")}
\item{value_col}{column name in \code{state_data} that holds the values to be plotted} \item{value_col}{column name in \code{state_data} that holds the values to be plotted}
\item{dark_label, light_label}{dark/light label colors. The specified color will be used \item{dark_label, light_label, na_label}{dark/light/NA label colors. The specified color will be used
when the algorithm determines labels should be inverted.} when the algorithm determines labels should be inverted.}
\item{font_size}{font size (default = \code{3})} \item{font_size}{font size (default = \code{3})}

BIN
tests/.DS_Store

Binary file not shown.
Loading…
Cancel
Save