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

v0.3.1 #37

Merged
merged 5 commits into from
Nov 1, 2019
Merged
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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**
Expand Down
121 changes: 68 additions & 53 deletions R/bulletchart.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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]]
Expand Down
4 changes: 2 additions & 2 deletions R/bulletchartr_data.r
Original file line number Diff line number Diff line change
@@ -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:
#'
Expand Down
2 changes: 1 addition & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
4 changes: 4 additions & 0 deletions R/internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -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("(+",
Expand Down
10 changes: 5 additions & 5 deletions R/internal_bc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)) {
Expand All @@ -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))
Expand All @@ -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")))
Expand Down
45 changes: 45 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
url: https://acdivocatech.github.io/bulletchartr/

template:
params:
bootswatch: simplex

home:
links:
- text: 'Visit <a href="https://www.acdivoca.org/"><img alt="ACDIVOCA" src="https://www.acdivoca.org/wp-content/themes/acdi/images/logo.png" width="70"></a> 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
Binary file modified data/bc_ex.rda
Binary file not shown.
26 changes: 10 additions & 16 deletions docs/404.html

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

Loading