Skip to content

Commit

Permalink
fix data for examples, references #25
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryo-N7 committed Oct 22, 2019
1 parent b682e2a commit 3c497f3
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 88 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -60,3 +59,4 @@ importFrom(testthat,expect_equal)
importFrom(testthat,expect_true)
importFrom(testthat,test_that)
importFrom(tidyr,nest)
importFrom(utils,head)
2 changes: 1 addition & 1 deletion R/bullet_chart_symbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
4 changes: 2 additions & 2 deletions R/bullet_chart_vline.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/bullet_chart_wide.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions R/bulletchart.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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() +
Expand All @@ -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}")) +
Expand Down
6 changes: 2 additions & 4 deletions R/bulletchartr_data.r
Original file line number Diff line number Diff line change
@@ -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:
#'
Expand All @@ -13,8 +12,7 @@
#'
#' }
#'
#' @docType data
#' @keywords datasets
#' @name df
#' @usage data(df)
NULL
"df"
1 change: 1 addition & 0 deletions R/internal_bc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") %>%
Expand Down
Binary file added data/df.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/bullet_chart_symbols.Rd

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

4 changes: 2 additions & 2 deletions man/bullet_chart_vline.Rd

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

4 changes: 2 additions & 2 deletions man/bullet_chart_wide.Rd

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

46 changes: 0 additions & 46 deletions man/bulletchart.Rd

This file was deleted.

16 changes: 8 additions & 8 deletions man/df.Rd

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

15 changes: 5 additions & 10 deletions tests/testthat/test_bullet_chart.r
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3c497f3

Please sign in to comment.