From 3c497f32047adcb160ab09822df4f29bc385fd4f Mon Sep 17 00:00:00 2001 From: Ryo-N7 Date: Tue, 22 Oct 2019 22:32:27 +0900 Subject: [PATCH] fix data for examples, references #25 --- NAMESPACE | 2 +- R/bullet_chart_symbols.R | 2 +- R/bullet_chart_vline.R | 4 +-- R/bullet_chart_wide.R | 4 +-- R/bulletchart.R | 21 +++++++------ R/bulletchartr_data.r | 6 ++-- R/internal_bc.R | 1 + data/df.rda | Bin 0 -> 261 bytes man/bullet_chart_symbols.Rd | 2 +- man/bullet_chart_vline.Rd | 4 +-- man/bullet_chart_wide.Rd | 4 +-- man/bulletchart.Rd | 46 ----------------------------- man/df.Rd | 16 +++++----- tests/testthat/test_bullet_chart.r | 15 ++++------ 14 files changed, 39 insertions(+), 88 deletions(-) create mode 100644 data/df.rda delete mode 100644 man/bulletchart.Rd 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 0000000000000000000000000000000000000000..bb9306a8f10736bbe53869680c9188c238a31df0 GIT binary patch literal 261 zcmV+g0s8(QiwFP!000001`BeDFye~fVqjokVqj)rW?*6lGFg~_1S10r11Cs4C5?fB zSs2J-1!4gpW`oMGdFG`k7?_~&Oi_5|$UH+s6dtOa1(3xD;yG|IfPq7G0E9My^4%b` z{Rb%ja0devpz5n~fY3$^DEbNN^F&qeFy8^cJ{_od2-H4PDF29d1DF