Skip to content

Commit

Permalink
fix interactive, fix show_text, add bc regular data, add "info" into …
Browse files Browse the repository at this point in the history
…regular bc df, edit readme and all vignettes, references #33, references #17, references #25, references #31
  • Loading branch information
Ryo-N7 committed Oct 24, 2019
1 parent 3c497f3 commit ed4fd2b
Show file tree
Hide file tree
Showing 23 changed files with 339 additions and 278 deletions.
14 changes: 5 additions & 9 deletions R/bullet_chart_symbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ bullet_chart_symbols <- function(file_name = NULL, sheet_name = "Sheet1",
legend.key.size = unit(0.8, "lines"))

if (show_text == TRUE) {
g
warning("When 'small' is set to TRUE, text will not show up by default! \n")
}

Expand Down Expand Up @@ -207,7 +206,6 @@ bullet_chart_symbols <- function(file_name = NULL, sheet_name = "Sheet1",
legend.key.size = unit(1.5, "lines"))

if (show_text == TRUE) {
g
warning("When 'chart_type' is set to 'interactive', text will not show up by default! \n")
}

Expand All @@ -216,18 +214,17 @@ bullet_chart_symbols <- function(file_name = NULL, sheet_name = "Sheet1",
g <- g + theme(legend.position = "none")

output <- girafe(code = {print(g)},
width = 0.5
width_svg = 12
)
output

} else if (legend == TRUE) {

g <- g + guides(shape = guide_legend(nrow = 1)) + theme(legend.position = "bottom")
output <- girafe(code = {print(g)},
width = 0.5
width_svg = 12
)
output

}

} else if (small == TRUE) {
Expand All @@ -252,24 +249,23 @@ bullet_chart_symbols <- function(file_name = NULL, sheet_name = "Sheet1",
legend.key.size = unit(0.8, "lines"))

if (show_text == TRUE) {
g
warning("When 'chart_type' is set to 'interactive', text will not show up by default! \n")
warning("When 'chart_type' is set to 'interactive', text will not show up by default! \n")
}

if (legend == FALSE) {

g <- g + theme(legend.position = "none")

output <- girafe(code = {print(g)},
width = 0.4
width_svg = 20
)
output

} else if (legend == TRUE) {

g <- g + guides(shape = guide_legend(nrow = 1)) + theme(legend.position = "bottom")
output <- girafe(code = {print(g)},
width = 0.4
width_svg = 20
)
output
}
Expand Down
12 changes: 4 additions & 8 deletions R/bullet_chart_vline.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ bullet_chart_vline <- function(file_name = NULL, sheet_name = "Sheet1",
g <- g +
geom_point(aes(y = perc_year, shape = "Last Year"), size = 4.5, stroke = 3) +
scale_shape_manual(" ", values = 124) +
geom_text(y = 1, aes(label = tooltip), vjust = -1.5, hjust = 0) +
annotate("text", x = 0, y = ammended_data$percent_time + 1.5,
hjust = 0, label = "Today", angle = 90, alpha = 0.5, size = 5) +
theme(axis.text.y = element_text(size = 15, face = "bold"),
Expand Down Expand Up @@ -135,7 +134,6 @@ bullet_chart_vline <- function(file_name = NULL, sheet_name = "Sheet1",
legend.key.size = unit(0.8, "lines"))

if (show_text == TRUE) {
g
warning("When 'small' is set to TRUE, text will not show up by default! \n")
}

Expand Down Expand Up @@ -190,7 +188,6 @@ bullet_chart_vline <- function(file_name = NULL, sheet_name = "Sheet1",
plot.subtitle = element_text(hjust = 0.5, size = 8))

if (show_text == TRUE) {
g
warning("When 'chart_type' is set to 'interactive', text will not show up by default! \n")
}

Expand All @@ -199,15 +196,15 @@ bullet_chart_vline <- function(file_name = NULL, sheet_name = "Sheet1",
g <- g + theme(legend.position = "none")

output <- girafe(code = {print(g)},
width = 0.4
width_svg = 12
)
output

} else if (legend == TRUE) {

g <- g + guides(shape = guide_legend(nrow = 1)) + theme(legend.position = "bottom")
output <- girafe(code = {print(g)},
width = 0.4
width_svg = 12
)
output

Expand All @@ -231,7 +228,6 @@ bullet_chart_vline <- function(file_name = NULL, sheet_name = "Sheet1",
legend.key.size = unit(0.8, "lines"))

if (show_text == TRUE) {
g
warning("When 'chart_type' is set to 'interactive', text will not show up by default! \n")
}

Expand All @@ -240,15 +236,15 @@ bullet_chart_vline <- function(file_name = NULL, sheet_name = "Sheet1",
g <- g + theme(legend.position = "none")

output <- girafe(code = {print(g)},
width = 0.4
width_svg = 20
)
output

} else if (legend == TRUE) {

g <- g + guides(shape = guide_legend(nrow = 1)) + theme(legend.position = "bottom")
output <- girafe(code = {print(g)},
width = 0.4
width_svg = 20
)
output

Expand Down
11 changes: 4 additions & 7 deletions R/bullet_chart_wide.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ bullet_chart_wide <- function(file_name = NULL, sheet_name = "Sheet1",
legend.key.size = unit(0.8, "lines"))

if (show_text == TRUE) {
g
warning("When 'small' is set to TRUE, text will not show up by default! \n")
}

Expand Down Expand Up @@ -182,7 +181,6 @@ bullet_chart_wide <- function(file_name = NULL, sheet_name = "Sheet1",
plot.subtitle = element_text(hjust = 0.5, size = 8))

if (show_text == TRUE) {
g
warning("When 'chart_type' is set to 'interactive', text will not show up by default! \n")
}

Expand All @@ -191,15 +189,15 @@ bullet_chart_wide <- function(file_name = NULL, sheet_name = "Sheet1",
g <- g + theme(legend.position = "none")

output <- girafe(code = {print(g)},
width = 0.5
width_svg = 12
)
output

} else if (legend == TRUE) {

g <- g + guides(shape = guide_legend(nrow = 1)) + theme(legend.position = "bottom")
output <- girafe(code = {print(g)},
width = 0.5
width_svg = 12
)
output

Expand Down Expand Up @@ -231,7 +229,6 @@ bullet_chart_wide <- function(file_name = NULL, sheet_name = "Sheet1",
legend.key.size = unit(0.8, "lines"))

if (show_text == TRUE) {
g
warning("When 'chart_type' is set to 'interactive', text will not show up by default! \n")
}

Expand All @@ -240,15 +237,15 @@ bullet_chart_wide <- function(file_name = NULL, sheet_name = "Sheet1",
g <- g + theme(legend.position = "none")

output <- girafe(code = {print(g)},
width = 0.5
width_svg = 20
)
output

}else if (legend == TRUE){

g <- g + guides(shape = guide_legend(nrow = 1)) + theme(legend.position = "bottom")
output <- girafe(code = {print(g)},
width = 0.5
width_svg = 20
)
output

Expand Down
7 changes: 5 additions & 2 deletions R/bulletchart.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#' @param legend PARAM_DESCRIPTION, Default: TRUE
#' @return bullet chart plot(s)
#' @details Stephen Few style bullet chart
#' @examples
#' data("df_bc")
#' bullet_chart(dataframe = df_bc)
#' @rdname bullet_chart
#' @export
#' @importFrom ggplot2 ggplot geom_col aes geom_segment coord_flip
Expand Down Expand Up @@ -103,10 +106,10 @@ bullet_chart <- function(file_name = NULL, sheet_name = "Sheet1",
breaks = seqbreaks) +
scale_x_continuous(expand = c(0, 0)) +
scale_fill_manual(values = cols, name = NULL,
labels = c("Current", "High", "Medium", "Low")) +
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$var_info}")) +
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),
Expand Down
25 changes: 24 additions & 1 deletion R/bulletchartr_data.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' example dataframe of indicators and targets
#' @format 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 @@ -16,3 +17,25 @@
#' @name df
#' @usage data(df)
"df"

#' example dataframe for regular scale bullet chart
#' @format This data set contains indicator values and target data
#' used in the examples in README for the regular scale bullet charts.
#'
#' The variables are as follows:
#'
#' \itemize{
#' \item variable. name of the indicator
#' \item info. extra info about indicator
#' \item target. target value of indicator
#' \item current. current value of indicator
#' \item low. low value of indicator
#' \item medium. medium value of indicator
#' \item high. high value of indicator
#'
#' }
#'
#' @keywords datasets
#' @name df_bc
#' @usage data(df_bc)
"df_bc"
13 changes: 9 additions & 4 deletions R/internal_bc.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ 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
Expand Down Expand Up @@ -101,14 +102,18 @@ field_calculator <- function(file_name = NULL, sheet_name = "Sheet1",
## reshape
ammended_data <- ammended_data %>%
select(-tarhigh) %>%
tidyr::pivot_longer(-c(indicator_name, target),
tidyr::pivot_longer(-c(indicator_name, target, info),
names_to = "allvals",
values_to = "vals") %>%
dplyr::mutate(allvals = forcats::as_factor(allvals))

# Variable info text:
## Variable info text
## relevel qualitative labels so show up in order on legend
## ammended_data$allvals %>% levels()
ammended_data <- ammended_data %>%
mutate(varinfo = glue("{indicator_name}: {info}"))
mutate(varinfo = glue("{indicator_name}: {info}")) %>%
mutate(allvals = forcats::fct_relevel(allvals,
c("Current", "High", "Medium", "Low")))

# ammended_data <- ammended_data %>%
# mutate(allvals = forcats::fct_relevel(allvals, c("Current", "High", "Medium", "Low")))
Expand Down
80 changes: 41 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,67 @@ coverage](https://codecov.io/gh/ACDIVOCATech/bulletchartr/branch/master/graph/ba
Status](https://travis-ci.org/ACDIVOCATech/bulletchartr.svg?branch=master)](https://travis-ci.org/ACDIVOCATech/bulletchartr)
<!-- badges: end -->

## What is a bullet chart?
This package, `bulletchartr` is based on visualizing M\&E deliverables
or “Indicators”, however, it can be handy for anyone that depends on
monitoring Key Performance Indicators (KPIs) or needs to track progress
against different targets.

## Installation

``` r
# Install the package from GitHub:
# install.packages("devtools")

devtools::install_github("ACDIVOCATech/bulletchartr")
```

The **bullet chart** was invented by [Stephen
Few](https://www.perceptualedge.com/articles/misc/Bullet_Graph_Design_Spec.pIndicatorData),
for the purpose of showing tons of info in a condensed form in KPIs.

This type of graph is a variation on a typical bar graph with a thick
line presenting an important point for that indicator (benchmark,
performance target, etc.) and other bars in the background that can
signify different levels of performance (low-high, bad-good, etc.). The
bullet chart makes it very easy to compare between related measures
(e.g. present status versus status at similar time in the past).

The output of the `bullet_chart()` function most closely resembles
Stephen Few’s design:

``` r
bullet_chart(file_name = read_example("Indicators_Targets_ext.xlsx"))
## load example data
load(read_example("df_bc.rda"))

bullet_chart(dataframe = df_bc)
```

<img src="man/figures/README-bulletchart-1.png" width="100%" />

The single black bar represents the current value of the indicator while
the different hue columns represent last week’s value (darker hue) and
last year’s value (lighter hue). The bar for each Indicator show the
progression along the horizontal-axis presenting the percentage of the
yearly target completed. This axis also shows the percent of the year
gone by with the vertical line indicating what exact percentage “Today”
is, along this percentage.

As you can see, the bars show the progression along the horizontal-axis
presenting the percentage of the yearly target completed. Also, along
this axis is the percent of the year gone by with a vertical line
indicating what exact percentage **“Today”** is along this percentage.
It is necessary to use percentages as we have multiple indicators of
varying units/parameters for each project\!

The different grey colored bars represent the values of the indicator at
“Last Week” and “Last Year”. The grey scaled bars can represent any
qualitative ranges such as “bad - good - excellent” or “disabled -
repairing - fixed”, etc. In the near future we will look to expand the
capabilities of this package to allow users to specify these qualitative
ranges to fit their needs.
The outputs of `bullet_chart_symbols()`, `bullet_chart_wide()`, and
`bullet_chart_vline()` have a different x-axis scale to a regular bullet
chart.

This package, `bulletchartr` is based on visualizing M\&E deliverables
or “Indicators”, however, it can be handy for anyone that depends on
monitoring Key Performance Indicators (KPIs) or needs to track progress
against different targets.
The x-axis represents both the percentage of the yearly target AND the
percentage of the year that has passed. There is a vertical line showing
`TODAY`, which shows at what percentage of the year **and** what
percentage of the target we are at right now. The color inside the bar
is **green** if we are near or past the `TODAY` line, **orange** when
we’re close and **red** when we’re very behind schedule/target.

## Installation
``` r
bullet_chart_symbols(file_name = read_example("Indicators_Targets_ext.xlsx"))
```

<img src="man/figures/README-unnamed-chunk-1-1.png" width="100%" />

``` r
# Install the package from GitHub:
# install.packages("devtools")
bullet_chart_wide(file_name = read_example("Indicators_Targets_ext.xlsx"))
```

devtools::install_github("ACDIVOCATech/bulletchartr")
<img src="man/figures/README-unnamed-chunk-2-1.png" width="100%" />

``` r
bullet_chart_vline(file_name = read_example("Indicators_Targets_ext.xlsx"))
```

(picture of all 4 types)
<img src="man/figures/README-unnamed-chunk-3-1.png" width="100%" />

Please read the package vignette, “Introduction to bullet charts” for a
more detailed overview\!

## Future direction

Expand Down
Loading

0 comments on commit ed4fd2b

Please sign in to comment.