зеркало из https://github.com/microsoft/wpa.git
feat: add legend_lab
Enables the legend label to be over-ridden in a single HR attribute mode for `create_inc()`
This commit is contained in:
Родитель
ff9713b4ee
Коммит
8dca7139cd
|
@ -33,6 +33,8 @@
|
|||
#' percentage signs. Defaults to `FALSE`.
|
||||
#' @param plot_title An option to override plot title.
|
||||
#' @param plot_subtitle An option to override plot subtitle.
|
||||
#' @param legend_lab String. Option to override legend title/label. Defaults to
|
||||
#' `NULL`, where the metric name will be populated instead.
|
||||
#' @param rank String specifying how to rank the bars. Valid inputs are:
|
||||
#' - `"descending"` - ranked highest to lowest from top to bottom (default).
|
||||
#' - `"ascending"` - ranked lowest to highest from top to bottom.
|
||||
|
@ -92,6 +94,7 @@ create_bar <- function(data,
|
|||
percent = FALSE,
|
||||
plot_title = us_to_space(metric),
|
||||
plot_subtitle = paste("Average by", tolower(camel_clean(hrvar))),
|
||||
legend_lab = NULL,
|
||||
rank = "descending",
|
||||
xlim = NULL,
|
||||
text_just = 0.5,
|
||||
|
@ -107,6 +110,11 @@ create_bar <- function(data,
|
|||
data %>%
|
||||
check_inputs(requirements = required_variables)
|
||||
|
||||
## Handle `legend_lab`
|
||||
if(is.null(legend_lab)){
|
||||
legend_lab <- gsub("_", " ", metric)
|
||||
}
|
||||
|
||||
## Handling NULL values passed to hrvar
|
||||
if(is.null(hrvar)){
|
||||
data <- totals_col(data)
|
||||
|
@ -148,13 +156,14 @@ create_bar <- function(data,
|
|||
## Bar plot
|
||||
plot_object <- data %>%
|
||||
create_stacked(
|
||||
metrics=metric,
|
||||
metrics = metric,
|
||||
hrvar = hrvar,
|
||||
mingroup = mingroup,
|
||||
stack_colours = bar_colour,
|
||||
percent = percent,
|
||||
plot_title = plot_title,
|
||||
plot_subtitle = plot_subtitle,
|
||||
legend_lab = legend_lab,
|
||||
return = "plot",
|
||||
rank = rank,
|
||||
xlim = xlim,
|
||||
|
|
|
@ -158,6 +158,9 @@ create_inc_bar <- function(
|
|||
return = return,
|
||||
plot_title = title_text,
|
||||
plot_subtitle = subtitle_text,
|
||||
legend_lab = paste(us_to_space(metric),
|
||||
position,
|
||||
threshold),
|
||||
percent = TRUE
|
||||
)
|
||||
}
|
||||
|
@ -222,6 +225,8 @@ create_inc_grid <- function(
|
|||
hrvar[2]
|
||||
)
|
||||
|
||||
metric_text <- NULL
|
||||
|
||||
myTable %>%
|
||||
mutate(metric_text = paste0(
|
||||
scales::percent(!!sym(metric), accuracy = 1),
|
||||
|
|
|
@ -23,8 +23,10 @@
|
|||
#' A character vector to specify the colour codes for the stacked bar charts.
|
||||
#' @param percent Logical value to determine whether to show labels as
|
||||
#' percentage signs. Defaults to `FALSE`.
|
||||
#' @param plot_title An option to override plot title.
|
||||
#' @param plot_subtitle An option to override plot subtitle.
|
||||
#' @param plot_title String. Option to override plot title.
|
||||
#' @param plot_subtitle String. Option to override plot subtitle.
|
||||
#' @param legend_lab String. Option to override legend title/label. Defaults to
|
||||
#' `NULL`, where the metric name will be populated instead.
|
||||
#' @param rank String specifying how to rank the bars. Valid inputs are:
|
||||
#' - `"descending"` - ranked highest to lowest from top to bottom (default).
|
||||
#' - `"ascending"` - ranked lowest to highest from top to bottom.
|
||||
|
@ -86,6 +88,7 @@ create_stacked <- function(data,
|
|||
percent = FALSE,
|
||||
plot_title = "Collaboration Hours",
|
||||
plot_subtitle = paste("Average by", tolower(camel_clean(hrvar))),
|
||||
legend_lab = NULL,
|
||||
rank = "descending",
|
||||
xlim = NULL,
|
||||
text_just = 0.5,
|
||||
|
@ -102,6 +105,11 @@ create_stacked <- function(data,
|
|||
data %>%
|
||||
check_inputs(requirements = required_variables)
|
||||
|
||||
## Handle `legend_lab`
|
||||
if(is.null(legend_lab)){
|
||||
legend_lab <- gsub("_", " ", metrics)
|
||||
}
|
||||
|
||||
## Handling NULL values passed to hrvar
|
||||
if(is.null(hrvar)){
|
||||
data <- totals_col(data)
|
||||
|
@ -251,7 +259,7 @@ create_stacked <- function(data,
|
|||
scale_fill_manual(name="",
|
||||
values = stack_colours,
|
||||
breaks = metrics,
|
||||
labels = gsub("_", " ", metrics)) +
|
||||
labels = legend_lab) +
|
||||
coord_flip() +
|
||||
theme_wpa_basic() +
|
||||
theme(axis.line = element_blank(),
|
||||
|
|
|
@ -15,6 +15,7 @@ create_bar(
|
|||
percent = FALSE,
|
||||
plot_title = us_to_space(metric),
|
||||
plot_subtitle = paste("Average by", tolower(camel_clean(hrvar))),
|
||||
legend_lab = NULL,
|
||||
rank = "descending",
|
||||
xlim = NULL,
|
||||
text_just = 0.5,
|
||||
|
@ -58,6 +59,9 @@ percentage signs. Defaults to \code{FALSE}.}
|
|||
|
||||
\item{plot_subtitle}{An option to override plot subtitle.}
|
||||
|
||||
\item{legend_lab}{String. Option to override legend title/label. Defaults to
|
||||
\code{NULL}, where the metric name will be populated instead.}
|
||||
|
||||
\item{rank}{String specifying how to rank the bars. Valid inputs are:
|
||||
\itemize{
|
||||
\item \code{"descending"} - ranked highest to lowest from top to bottom (default).
|
||||
|
|
|
@ -14,6 +14,7 @@ create_stacked(
|
|||
percent = FALSE,
|
||||
plot_title = "Collaboration Hours",
|
||||
plot_subtitle = paste("Average by", tolower(camel_clean(hrvar))),
|
||||
legend_lab = NULL,
|
||||
rank = "descending",
|
||||
xlim = NULL,
|
||||
text_just = 0.5,
|
||||
|
@ -43,9 +44,12 @@ Valid inputs are "plot" and "table".}
|
|||
\item{percent}{Logical value to determine whether to show labels as
|
||||
percentage signs. Defaults to \code{FALSE}.}
|
||||
|
||||
\item{plot_title}{An option to override plot title.}
|
||||
\item{plot_title}{String. Option to override plot title.}
|
||||
|
||||
\item{plot_subtitle}{An option to override plot subtitle.}
|
||||
\item{plot_subtitle}{String. Option to override plot subtitle.}
|
||||
|
||||
\item{legend_lab}{String. Option to override legend title/label. Defaults to
|
||||
\code{NULL}, where the metric name will be populated instead.}
|
||||
|
||||
\item{rank}{String specifying how to rank the bars. Valid inputs are:
|
||||
\itemize{
|
||||
|
|
Загрузка…
Ссылка в новой задаче