Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #48 #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Encoding: UTF-8
LazyData: true
Imports:
classInt,
ggplot2
RoxygenNote: 7.2.0
ggplot2,
rlang
RoxygenNote: 7.3.2
Suggests:
covr,
cowplot,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export(bi_pal_manual)
export(bi_scale_color)
export(bi_scale_fill)
export(bi_theme)
importFrom(rlang,ensym)
14 changes: 10 additions & 4 deletions R/bi_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#' # summarize quantile breaks, 3x3
#' table(data$bi_class)
#'
#' @importFrom rlang ensym
#'
#' @export
bi_class <- function(.data, x, y, style, dim = 3, keep_factors = FALSE, dig_lab = 3, na_rm = FALSE){

Expand Down Expand Up @@ -98,8 +100,9 @@ bi_class <- function(.data, x, y, style, dim = 3, keep_factors = FALSE, dig_lab
}

# nse
xQN <- as.character(substitute(x))
yQN <- as.character(substitute(y))
#browser()
xQN <- as.character(rlang::ensym(x))
yQN <- as.character(rlang::ensym(y))

# evaluate inputs
bi_var_validate(.data, var = xQN, dim = dim, style = style)
Expand Down Expand Up @@ -259,8 +262,9 @@ bi_class_breaks <- function(.data, x, y, style, dim = 3, clean_levels = TRUE,
si_vals <- bi_validate_si_levels(si_levels = si_levels)

# nse
xQN <- as.character(substitute(x))
yQN <- as.character(substitute(y))
#browser()
xQN <- as.character(rlang::ensym(x))
yQN <- as.character(rlang::ensym(y))

# evaluate inputs
bi_var_validate(.data, var = xQN, dim = dim, style = style)
Expand Down Expand Up @@ -292,6 +296,8 @@ bi_class_breaks <- function(.data, x, y, style, dim = 3, clean_levels = TRUE,
# validate variable input
bi_var_validate <- function(.data, var, dim, style){

#browser()

if (var %in% names(.data) == FALSE){
stop(paste0("The variable '", var, "' is not found in the given data set."))
}
Expand Down
4 changes: 2 additions & 2 deletions R/bi_theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bi_theme <- function(base_family = "sans", base_size = 24, bg_color = "#ffffff",
axis.ticks = ggplot2::element_blank(),

# add a grid that blends into plot background
panel.grid.major = ggplot2::element_line(color = bg_color, size = 0.2),
panel.grid.major = ggplot2::element_line(color = bg_color, linewidth = 0.2),
panel.grid.minor = ggplot2::element_blank(),

# background colors
Expand Down Expand Up @@ -84,7 +84,7 @@ bi_theme_legend <- function(base_family = "sans", base_size = 24, bg_color = "#f
axis.ticks = ggplot2::element_line(),

# add a grid that blends into plot background
panel.grid.major = ggplot2::element_line(color = bg_color, size = 0.2),
panel.grid.major = ggplot2::element_line(color = bg_color, linewidth = 0.2),
panel.grid.minor = ggplot2::element_blank(),

# background colors
Expand Down
4 changes: 4 additions & 0 deletions man/bi_class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/testthat/test_bi_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,17 @@ test_that("high dimension inputs generate warning", {
expect_warning(bi_class(stl_race_income, x = pctWhite, y = medInc, style = "quantile", dim = 5),
"Maps that are larger than 4x4 dimensions can be difficult to interpret, and biscale does not provide built-in palettes for these maps. If you proceed, you will need to supply a custom palette for these data.")
})


# test variable inputs ----------------------------------------------------

var.inputs <- list( input1 = "medInc"
,input2 = "pctWhite")

test_that("Allow variable inputs", {
expect_equal(
bi_class(stl_race_income, x = pctWhite, y = medInc, style = "quantile", dim = 2),
bi_class(stl_race_income, x = !!var.inputs$input2, y = !!var.inputs$input1, style = "quantile", dim = 2)
)
})