diff --git a/DESCRIPTION b/DESCRIPTION index 542c356..d21c2f6 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bulletchartr Type: Package Title: Create Bullet Charts For Visualizing KPIs -Version: 0.3.0 +Version: 0.3.1 Authors@R: c(person("Ryo", "Nakagawara", email = "ryonakagawara@gmail.com", role = c("aut", "cre")), person("Amit", "Kohli", email= "mexindian@gmail.com", diff --git a/NEWS.md b/NEWS.md index 09c96e0..66fd059 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# bulletchartr 0.3.1 + +* Added legend entry for "Target" as per [#24](https://github.com/ACDIVOCATech/bulletchartr/issues/24) +* Fixed [#34](https://github.com/ACDIVOCATech/bulletchartr/issues/34) regarding 'Unknown or uninitialized column' warnings +* Reordered items in legend as per [#36](https://github.com/ACDIVOCATech/bulletchartr/issues/36) +* Updated README +* pkgdown website updated +* Update package logo with new target legend changes + # bulletchartr 0.3.0 * `bullet_chart()` function now uses regular scale **only** diff --git a/R/bulletchart.R b/R/bulletchart.R index f0cfc4c..869baa6 100644 --- a/R/bulletchart.R +++ b/R/bulletchart.R @@ -51,11 +51,11 @@ bullet_chart <- function(file_name = NULL, sheet_name = "Sheet1", target, remove_no_targets) ## check for Target == 0 in all Targets - if(all(ammended_data$target == 0)) { - return( - "No Non-Zero Targets!" - ) - } + # if(all(ammended_data %>% filter(allvals == "Target") %>% select(vals) %>% pull() == 0)) { + # return( + # "No Non-Zero Targets!" + # ) + # } ## grab the names of all the indicators indicator_vector <- ammended_data$indicator_name %>% unique() @@ -77,55 +77,69 @@ bullet_chart <- function(file_name = NULL, sheet_name = "Sheet1", ## fill colors cols <- c(High = "#dcdcdc", Medium = "#c0c0c0", Low = "#696969", - Current = "black") + Current = "black", Target = "red") ## PLOT - g <- data %>% - ggplot() + - ## great - geom_col(data = data %>% filter(allvals == "High"), - aes(x = 1, y = vals, fill = allvals)) + - ## good - geom_col(data = data %>% filter(allvals == "Medium"), - aes(x = 1, y = vals, fill = allvals)) + - ## bad - geom_col(data = data %>% filter(allvals == "Low"), - aes(x = 1, y = vals, fill = allvals)) + - ## current - geom_col(data = data %>% filter(allvals == "Current"), - aes(x = 1, y = vals, fill = allvals), - width = 0.2) + - ## target - geom_segment(aes(x = 0.75, xend = 1.25, - y = target, yend = target), - color = "red", size = 2.5) + - coord_flip() + - scale_y_continuous(limits = c(0, NA), - expand = c(0, 0), - labels = seqbreaks, - breaks = seqbreaks) + - scale_x_continuous(expand = c(0, 0)) + - scale_fill_manual(values = cols, name = NULL, - breaks = 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$varinfo}")) + - theme(title = element_text(face = "bold"), - plot.title = element_text(hjust = 0.5), - plot.subtitle = element_text(hjust = 0.5, size = 8), - panel.grid = element_blank(), - axis.title.x = element_blank(), - axis.text.x = element_text(face = "bold", size = 12), - axis.title.y = element_blank(), - axis.text.y = element_blank(), - axis.ticks.y = element_blank(), - strip.text = element_text(face = "bold", size = 14), - strip.background = element_rect(fill = "white"), - plot.margin = margin(1, 1, 1, 1, "cm"), - legend.position = "bottom", - legend.direction = "horizontal") - - return(g) + g <- suppressWarnings( + data %>% + ggplot() + + ## great + geom_col(data = data %>% filter(allvals == "High"), + aes(x = 1, y = vals, fill = allvals)) + + ## good + geom_col(data = data %>% filter(allvals == "Medium"), + aes(x = 1, y = vals, fill = allvals)) + + ## bad + geom_col(data = data %>% filter(allvals == "Low"), + aes(x = 1, y = vals, fill = allvals)) + + ## current + geom_col(data = data %>% filter(allvals == "Current"), + aes(x = 1, y = vals, fill = allvals), + width = 0.2) + + ## target + # geom_point(data = data %>% filter(allvals == "Target"), + # aes(x = 1, y = vals, fill = allvals), + # shape = 22, size = 4.5, color = "red", + # show.legend = FALSE) + + geom_segment(data = data %>% filter(allvals == "Target"), + aes(x = 0.75, xend = 1.25, + y = vals, yend = vals, fill = allvals), + color = "red", size = 2.5) + + # geom_rect(data = data %>% filter(allvals == "Target"), + # aes(xmin = 0.75, xmax = 1.25, + # ymin = vals * -0.25, ymax = vals * 0.25, + # fill = allvals), + # size = 2.5, show.legend = FALSE) + + coord_flip() + + scale_y_continuous(limits = c(0, NA), + expand = c(0.01, 0), + labels = seqbreaks, + breaks = seqbreaks) + + scale_x_continuous(expand = c(0, 0)) + + scale_fill_manual(values = cols, name = NULL, + breaks = c("Low", "Medium", "High", "Current", "Target")) + + ## var_info takes Indicator name AND any extra info provided in + ## the 'info' variable, all calculated in `field_calculator()` + labs(title = glue::glue("{data$varinfo}")) + + theme(title = element_text(face = "bold"), + plot.title = element_text(hjust = 0.5), + plot.subtitle = element_text(hjust = 0.5, size = 8), + panel.grid = element_blank(), + axis.title.x = element_blank(), + axis.text.x = element_text(face = "bold", size = 12), + axis.title.y = element_blank(), + axis.text.y = element_blank(), + axis.ticks.y = element_blank(), + strip.text = element_text(face = "bold", size = 14), + strip.background = element_rect(fill = "white"), + plot.margin = margin(1, 1, 1, 1, "cm"), + panel.background = element_rect(fill = "white"), + legend.text = element_text(face = "bold", size = 12), + legend.position = "bottom", + legend.direction = "horizontal") + ) + + #print(g) } ## map over each indicator @@ -137,7 +151,8 @@ bullet_chart <- function(file_name = NULL, sheet_name = "Sheet1", group_by(indicator_name) %>% nest() %>% mutate(plot = map2(data, indicator_name, - ~bc_plotter(data = .x, indicator_name = .y))) + ~ bc_plotter(data = .x, indicator_name = .y) + )) # plots_df$plot[[1]] # plots_df$plot[[2]] # plots_df$plot[[3]] diff --git a/R/bulletchartr_data.r b/R/bulletchartr_data.r index 0975dee..1e04b62 100644 --- a/R/bulletchartr_data.r +++ b/R/bulletchartr_data.r @@ -1,6 +1,6 @@ -#' example dataframe of indicators and targets +#' example dataframe for time-comparison scale bullet chart #' @format This data set contains indicator values and target data -#' used in the examples in README. +#' used in the examples in README for the time-comparison scale bullet charts. #' #' The variables are as follows: #' diff --git a/R/globals.R b/R/globals.R index df5ea7d..53ffbb4 100644 --- a/R/globals.R +++ b/R/globals.R @@ -2,4 +2,4 @@ utils::globalVariables(c(".", "behind_by", "perc", "perc_week", "perc_year", "percent_time", "text", "tooltip", "tooltip2", "allvals", "vals", "data", - "plot", "Current", "tarhigh")) + "plot", "Current", "Target", "tarhigh")) diff --git a/R/internal.R b/R/internal.R index 601fd57..8865c6b 100755 --- a/R/internal.R +++ b/R/internal.R @@ -147,6 +147,10 @@ extra_field_calculator <- function(file_name = NULL, sheet_name = "Sheet1", TRUE ~ OldPer )) + ammended_data <- ammended_data %>% + mutate(LWeek_tex = NA, + LY_tex = NA) + ## Calculate how far behind LAST for text ammended_data$LWeek_tex[ ammended_data$BehindFromLastWeek > 0 & !is.na(ammended_data$BehindFromLastWeek)] <- paste("(+", diff --git a/R/internal_bc.R b/R/internal_bc.R index 8c62b27..0f1d1ba 100644 --- a/R/internal_bc.R +++ b/R/internal_bc.R @@ -69,14 +69,14 @@ field_calculator <- function(file_name = NULL, sheet_name = "Sheet1", Low = !!Low, Medium = !!Medium, High = !!High, - target = !!tar, + Target = !!tar, info = !!inf ) ## filter NO Target indicators if(remove_no_targets == TRUE) { ammended_data <- ammended_data %>% - filter(!is.na(target), target != 0) + filter(!is.na(Target), Target != 0) } else { ammended_data } @@ -87,7 +87,7 @@ field_calculator <- function(file_name = NULL, sheet_name = "Sheet1", ## if target value Higher than "High", move "High" to "Target" value ## high should not be higher than target ?? #mutate(High = if_else(target > High, target, High)) - mutate(tarhigh = dplyr::if_else(target > High, TRUE, FALSE)) + mutate(tarhigh = dplyr::if_else(Target > High, TRUE, FALSE)) ## if Target > High then error out with name of columns if (any(ammended_data$tarhigh == TRUE)) { @@ -102,7 +102,7 @@ field_calculator <- function(file_name = NULL, sheet_name = "Sheet1", ## reshape ammended_data <- ammended_data %>% select(-tarhigh) %>% - tidyr::pivot_longer(-c(indicator_name, target, info), + tidyr::pivot_longer(-c(indicator_name, info), names_to = "allvals", values_to = "vals") %>% dplyr::mutate(allvals = forcats::as_factor(allvals)) @@ -113,7 +113,7 @@ field_calculator <- function(file_name = NULL, sheet_name = "Sheet1", ammended_data <- ammended_data %>% mutate(varinfo = glue("{indicator_name}: {info}")) %>% mutate(allvals = forcats::fct_relevel(allvals, - c("Current", "High", "Medium", "Low"))) + c("Low", "Medium", "High", "Current", "Target"))) # ammended_data <- ammended_data %>% # mutate(allvals = forcats::fct_relevel(allvals, c("Current", "High", "Medium", "Low"))) diff --git a/_pkgdown.yml b/_pkgdown.yml index cc74055..1650520 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1 +1,46 @@ url: https://acdivocatech.github.io/bulletchartr/ + +template: + params: + bootswatch: simplex + +home: + links: + - text: 'Visit ACDIVOCA website' + href: https://www.acdivoca.org/ + + +authors: + Ryo Nakagawara: + href: https://github.com/Ryo-N7 + Amit Kohli: + href: https://github.com/DataStrategist + +reference: + - title: Example data + contents: + - starts_with("bc_") + - matches("read_example") + - title: Bullet chart (regular scale) + contents: + - matches("bullet_chart()") + - title: Bullet chart (time-comparison scale) + contents: + - starts_with("bullet_chart_") + +navbar: + title: bulletchartr + type: default + left: + - text: Home + href: index.html + - text: Intro + href: articles/intro-to-bullet-charts.html + - text: Reference + href: reference/index.html + - text: Vignettes + menu: + - text: Intro to Inputs + href: articles/intro-inputs.html + - text: Intro to Arguments + href: articles/intro-arguments.html diff --git a/data/bc_ex.rda b/data/bc_ex.rda index 9a2e425..fb0f3f0 100644 Binary files a/data/bc_ex.rda and b/data/bc_ex.rda differ diff --git a/docs/404.html b/docs/404.html index f89bd90..cbead95 100644 --- a/docs/404.html +++ b/docs/404.html @@ -18,8 +18,8 @@ + - @@ -73,41 +73,35 @@ bulletchartr - 0.3.0 + 0.3.1