diff --git a/NAMESPACE b/NAMESPACE index d4351c1..1903b46 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,7 +4,6 @@ export(bullet_chart) export(bullet_chart_symbols) export(bullet_chart_vline) export(bullet_chart_wide) -export(bulletchart) export(read_example) importFrom(cowplot,get_legend) importFrom(cowplot,plot_grid) @@ -60,3 +59,4 @@ importFrom(testthat,expect_equal) importFrom(testthat,expect_true) importFrom(testthat,test_that) importFrom(tidyr,nest) +importFrom(utils,head) diff --git a/R/bullet_chart_symbols.R b/R/bullet_chart_symbols.R index b025f47..ebf1914 100644 --- a/R/bullet_chart_symbols.R +++ b/R/bullet_chart_symbols.R @@ -30,7 +30,7 @@ #' The symbols represent the indicator value for last week (diamond) and last year (circle). #' #' @examples -#' load(read_example("df.rda")) +#' data("df") #' bullet_chart_symbols(dataframe = df) #' @seealso #' \code{\link[ggplot2]{geom_bar}}, \code{\link[ggplot2]{scale_manual}} diff --git a/R/bullet_chart_vline.R b/R/bullet_chart_vline.R index 336f16d..0d8f239 100644 --- a/R/bullet_chart_vline.R +++ b/R/bullet_chart_vline.R @@ -26,8 +26,8 @@ #' general "target" value), however at the current time you should change the values of "actual_lastyear" #' in the Excel file but not the variable name itself. #' @examples -#' load(read_example("df.rda")) -#' bullet_chart_vline(dataframe = df) +#' data("df") +#' bullet_chart_symbols(dataframe = df) #' @rdname bullet_chart_vline #' @export #' @importFrom ggplot2 ggplot aes geom_col geom_hline coord_flip labs ggtitle theme_minimal diff --git a/R/bullet_chart_wide.R b/R/bullet_chart_wide.R index 2bd6953..9f94cf9 100644 --- a/R/bullet_chart_wide.R +++ b/R/bullet_chart_wide.R @@ -24,8 +24,8 @@ #' uses different thicknesses for the bars as the benchmarks for previous time points (last week and last year) to further #' accentuate the difference graphically. #' @examples -#' load(read_example("df.rda")) -#' bullet_chart_wide(dataframe = df) +#' data("df") +#' bullet_chart_symbols(dataframe = df) #' @seealso #' \code{\link[ggplot2]{geom_bar}} #' @rdname bullet_chart_wide diff --git a/R/bulletchart.R b/R/bulletchart.R index 7e1bfa5..2698236 100644 --- a/R/bulletchart.R +++ b/R/bulletchart.R @@ -54,10 +54,6 @@ bullet_chart <- function(file_name = NULL, sheet_name = "Sheet1", ) } - ## fill colors - cols <- c(High = "#dcdcdc", Medium = "#c0c0c0", Low = "#696969", - Current = "black") - ## grab the names of all the indicators indicator_vector <- ammended_data$indicator_name %>% unique() @@ -69,10 +65,17 @@ bullet_chart <- function(file_name = NULL, sheet_name = "Sheet1", max.bg <- max(data %>% filter(allvals == "High") %>% pull(vals)) - ## min max for 5 labels - sequence1 <- seq(min.bg, max.bg, length.out = 5) %>% signif(2) %>% head(-1) + ## min max for 6 labels + ## ex. Min == 1, 2, 3, 4, Max == 5 + sequence1 <- seq(min.bg, max.bg, length.out = 6) %>% signif(2) %>% head(-1) seqbreaks <- c(sequence1, max.bg) + # seq(min.bg, max.bg, length.out = 5) %>% floor() + + ## fill colors + cols <- c(High = "#dcdcdc", Medium = "#c0c0c0", Low = "#696969", + Current = "black") + ## PLOT g <- data %>% ggplot() + @@ -96,11 +99,11 @@ bullet_chart <- function(file_name = NULL, sheet_name = "Sheet1", coord_flip() + scale_y_continuous(limits = c(0, NA), expand = c(0, 0), - labels = seq(min.bg, max.bg, length.out = 5) %>% floor(), - breaks = seq(min.bg, max.bg, length.out = 5) %>% floor()) + + labels = seqbreaks, + breaks = seqbreaks) + scale_x_continuous(expand = c(0, 0)) + scale_fill_manual(values = cols, name = NULL, - breaks = c("Current", "High", "Medium", "Low")) + + labels = c("Current", "High", "Medium", "Low")) + ## var_info takes Indicator name AND any extra info provided in ## the 'info' variable, all calculated in `field_calculator()` labs(title = glue::glue("{data$var_info}")) + diff --git a/R/bulletchartr_data.r b/R/bulletchartr_data.r index 6a0f6db..ef45347 100644 --- a/R/bulletchartr_data.r +++ b/R/bulletchartr_data.r @@ -1,6 +1,5 @@ #' example dataframe of indicators and targets -#' -#' This data set contains indicator values and target data used in the examples in README. +#' @format This data set contains indicator values and target data used in the examples in README. #' #' The variables are as follows: #' @@ -13,8 +12,7 @@ #' #' } #' -#' @docType data #' @keywords datasets #' @name df #' @usage data(df) -NULL +"df" diff --git a/R/internal_bc.R b/R/internal_bc.R index 70bc75a..f30138f 100644 --- a/R/internal_bc.R +++ b/R/internal_bc.R @@ -100,6 +100,7 @@ field_calculator <- function(file_name = NULL, sheet_name = "Sheet1", ## reshape ammended_data <- ammended_data %>% + select(-tarhigh) %>% tidyr::pivot_longer(-c(indicator_name, target), names_to = "allvals", values_to = "vals") %>% diff --git a/data/df.rda b/data/df.rda new file mode 100644 index 0000000..bb9306a Binary files /dev/null and b/data/df.rda differ diff --git a/man/bullet_chart_symbols.Rd b/man/bullet_chart_symbols.Rd index 3426118..88056cf 100755 --- a/man/bullet_chart_symbols.Rd +++ b/man/bullet_chart_symbols.Rd @@ -60,7 +60,7 @@ it's close, and "red" if it is far off track. The symbols represent the indicator value for last week (diamond) and last year (circle). } \examples{ -load(read_example("df.rda")) +data("df") bullet_chart_symbols(dataframe = df) } \seealso{ diff --git a/man/bullet_chart_vline.Rd b/man/bullet_chart_vline.Rd index d9b86f6..6d2c6e3 100755 --- a/man/bullet_chart_vline.Rd +++ b/man/bullet_chart_vline.Rd @@ -57,6 +57,6 @@ general "target" value), however at the current time you should change the value in the Excel file but not the variable name itself. } \examples{ -load(read_example("df.rda")) -bullet_chart_vline(dataframe = df) +data("df") +bullet_chart_symbols(dataframe = df) } diff --git a/man/bullet_chart_wide.Rd b/man/bullet_chart_wide.Rd index 188b229..3b4dd13 100755 --- a/man/bullet_chart_wide.Rd +++ b/man/bullet_chart_wide.Rd @@ -55,8 +55,8 @@ uses different thicknesses for the bars as the benchmarks for previous time poin accentuate the difference graphically. } \examples{ -load(read_example("df.rda")) -bullet_chart_wide(dataframe = df) +data("df") +bullet_chart_symbols(dataframe = df) } \seealso{ \code{\link[ggplot2]{geom_bar}} diff --git a/man/bulletchart.Rd b/man/bulletchart.Rd deleted file mode 100644 index 8f651dc..0000000 --- a/man/bulletchart.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bulletchart222.R -\name{bulletchart} -\alias{bulletchart} -\title{bulletchart} -\usage{ -bulletchart(file_name = NULL, sheet_name = "Sheet1", - dataframe = NULL, indicator_name = "variable", info = "info", - current = "current", low = "low", medium = "medium", - high = "high", target = "target", remove_no_targets = TRUE, - legend = TRUE) -} -\arguments{ -\item{file_name}{PARAM_DESCRIPTION, Default: NULL} - -\item{sheet_name}{PARAM_DESCRIPTION, Default: 'Sheet1'} - -\item{dataframe}{PARAM_DESCRIPTION, Default: NULL} - -\item{indicator_name}{PARAM_DESCRIPTION, Default: 'variable'} - -\item{info}{PARAM_DESCRIPTION, Default: 'info'} - -\item{current}{PARAM_DESCRIPTION, Default: 'current'} - -\item{low}{PARAM_DESCRIPTION, Default: 'low'} - -\item{medium}{PARAM_DESCRIPTION, Default: 'medium'} - -\item{high}{PARAM_DESCRIPTION, Default: 'high'} - -\item{target}{PARAM_DESCRIPTION, Default: 'target'} - -\item{remove_no_targets}{PARAM_DESCRIPTION, Default: TRUE} - -\item{legend}{PARAM_DESCRIPTION, Default: TRUE} -} -\value{ -OUTPUT_DESCRIPTION -} -\description{ -FUNCTION_DESCRIPTION -} -\details{ -Stephen Few style bullet chart -} diff --git a/man/df.Rd b/man/df.Rd index 1f093f2..2cedcb7 100755 --- a/man/df.Rd +++ b/man/df.Rd @@ -4,22 +4,22 @@ \name{df} \alias{df} \title{example dataframe of indicators and targets} -\usage{ -data(df) -} -\description{ -This data set contains indicator values and target data used in the examples in README. -} -\details{ +\format{This data set contains indicator values and target data used in the examples in README. + The variables are as follows: -\itemize{ + \itemize{ \item indicator_name. name of the indicator \item actual. present value of indicator \item actual_lastweek. value of indicator in previous week \item actual_lastyear. value of indicator on same day of last year \item target. target value of indicator + }} +\usage{ +data(df) } +\description{ +example dataframe of indicators and targets } \keyword{datasets} diff --git a/tests/testthat/test_bullet_chart.r b/tests/testthat/test_bullet_chart.r index 7a197f6..a134024 100755 --- a/tests/testthat/test_bullet_chart.r +++ b/tests/testthat/test_bullet_chart.r @@ -79,8 +79,7 @@ testthat::test_that("correct arguments used", { ## tests expect_error(bullet_chart(dataframe = bcdatatest, - legend = legend, - remove_no_targets = remove_no_targets), NA) + legend = legend), NA) expect_error(bullet_chart_symbols(dataframe = test_df, chart_type = chart_type, small = small, legend = legend, @@ -127,8 +126,7 @@ testthat::test_that("correct arguments used", { ## tests static expect_error(bullet_chart(dataframe = bcdatatest, - legend = legend, - remove_no_targets = remove_no_targets), NA) + legend = legend), NA) expect_error(bullet_chart_symbols(dataframe = test_df, chart_type = chart_type, small = small, legend = legend, @@ -175,8 +173,7 @@ testthat::test_that("correct arguments used", { ## tests static expect_error(bullet_chart(dataframe = bcdatatest, - legend = legend, - remove_no_targets = remove_no_targets), NA) + legend = legend), NA) expect_error(bullet_chart_symbols(dataframe = test_df, chart_type = chart_type, small = small, legend = legend, @@ -223,8 +220,7 @@ testthat::test_that("correct arguments used", { ## tests static expect_error(bullet_chart(dataframe = bcdatatest, - legend = legend, - remove_no_targets = remove_no_targets), NA) + legend = legend), NA) expect_error(bullet_chart_symbols(dataframe = test_df, chart_type = chart_type, small = small, legend = legend, @@ -266,8 +262,7 @@ testthat::test_that("correct arguments used", { ## static expect_error(bullet_chart(dataframe = bcdatatest, - legend = legend, - remove_no_targets = remove_no_targets), NA) + legend = legend), NA) expect_error(bullet_chart_symbols(dataframe = test_df, cal_type = cal_type, small = small, legend = legend,