зеркало из https://github.com/microsoft/wpa.git
feat: allow rounding digits for create_bar_asis
This commit is contained in:
Родитель
e2e2ca693e
Коммит
0a65352d2c
|
@ -26,6 +26,8 @@
|
||||||
#' In-built accepted values include "default" (default), "alert" (red), and
|
#' In-built accepted values include "default" (default), "alert" (red), and
|
||||||
#' "darkblue". Otherwise, hex codes are also accepted. You can also supply
|
#' "darkblue". Otherwise, hex codes are also accepted. You can also supply
|
||||||
#' RGB values via `rgb2hex()`.
|
#' RGB values via `rgb2hex()`.
|
||||||
|
#' @param rounding Numeric value to specify number of digits to show in data
|
||||||
|
#' labels
|
||||||
#'
|
#'
|
||||||
#' @return
|
#' @return
|
||||||
#' ggplot object. A horizontal bar plot.
|
#' ggplot object. A horizontal bar plot.
|
||||||
|
@ -43,7 +45,8 @@
|
||||||
#' title = "Total Meeting Hours over period",
|
#' title = "Total Meeting Hours over period",
|
||||||
#' subtitle = "By Organization",
|
#' subtitle = "By Organization",
|
||||||
#' caption = extract_date_range(sq_data, return = "text"),
|
#' caption = extract_date_range(sq_data, return = "text"),
|
||||||
#' bar_colour = "darkblue")
|
#' bar_colour = "darkblue",
|
||||||
|
#' rounding = 0)
|
||||||
#'
|
#'
|
||||||
#' @import ggplot2
|
#' @import ggplot2
|
||||||
#' @import dplyr
|
#' @import dplyr
|
||||||
|
@ -60,7 +63,8 @@ create_bar_asis <- function(data,
|
||||||
ylab = group_var,
|
ylab = group_var,
|
||||||
xlab = bar_var,
|
xlab = bar_var,
|
||||||
percent = FALSE,
|
percent = FALSE,
|
||||||
bar_colour = "default"){
|
bar_colour = "default",
|
||||||
|
rounding = 1){
|
||||||
|
|
||||||
## Colour bar override
|
## Colour bar override
|
||||||
if(bar_colour == "default"){
|
if(bar_colour == "default"){
|
||||||
|
@ -84,7 +88,7 @@ create_bar_asis <- function(data,
|
||||||
data %>%
|
data %>%
|
||||||
ggplot(aes(x = reorder(!!sym(group_var), !!sym(bar_var)), y = !!sym(bar_var))) +
|
ggplot(aes(x = reorder(!!sym(group_var), !!sym(bar_var)), y = !!sym(bar_var))) +
|
||||||
geom_col(fill = bar_colour) +
|
geom_col(fill = bar_colour) +
|
||||||
geom_text(aes(label = round(!!sym(bar_var), 2)),
|
geom_text(aes(label = round(!!sym(bar_var), digits = rounding)),
|
||||||
hjust = -0.25,
|
hjust = -0.25,
|
||||||
color = "#000000",
|
color = "#000000",
|
||||||
fontface = "bold",
|
fontface = "bold",
|
||||||
|
@ -94,7 +98,8 @@ create_bar_asis <- function(data,
|
||||||
data %>%
|
data %>%
|
||||||
ggplot(aes(x = reorder(!!sym(group_var), !!sym(bar_var)), y = !!sym(bar_var))) +
|
ggplot(aes(x = reorder(!!sym(group_var), !!sym(bar_var)), y = !!sym(bar_var))) +
|
||||||
geom_col(fill = bar_colour) +
|
geom_col(fill = bar_colour) +
|
||||||
geom_text(aes(label = scales::percent(!!sym(bar_var), accuracy = 1)),
|
geom_text(aes(label = scales::percent(!!sym(bar_var),
|
||||||
|
accuracy = 10 ^ -rounding)),
|
||||||
hjust = -0.25,
|
hjust = -0.25,
|
||||||
color = "#000000",
|
color = "#000000",
|
||||||
fontface = "bold",
|
fontface = "bold",
|
||||||
|
|
|
@ -14,7 +14,8 @@ create_bar_asis(
|
||||||
ylab = group_var,
|
ylab = group_var,
|
||||||
xlab = bar_var,
|
xlab = bar_var,
|
||||||
percent = FALSE,
|
percent = FALSE,
|
||||||
bar_colour = "default"
|
bar_colour = "default",
|
||||||
|
rounding = 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
|
@ -42,6 +43,9 @@ percentage signs. Defaults to FALSE.}
|
||||||
In-built accepted values include "default" (default), "alert" (red), and
|
In-built accepted values include "default" (default), "alert" (red), and
|
||||||
"darkblue". Otherwise, hex codes are also accepted. You can also supply
|
"darkblue". Otherwise, hex codes are also accepted. You can also supply
|
||||||
RGB values via \code{rgb2hex()}.}
|
RGB values via \code{rgb2hex()}.}
|
||||||
|
|
||||||
|
\item{rounding}{Numeric value to specify number of digits to show in data
|
||||||
|
labels}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
ggplot object. A horizontal bar plot.
|
ggplot object. A horizontal bar plot.
|
||||||
|
@ -65,7 +69,8 @@ sq_data \%>\%
|
||||||
title = "Total Meeting Hours over period",
|
title = "Total Meeting Hours over period",
|
||||||
subtitle = "By Organization",
|
subtitle = "By Organization",
|
||||||
caption = extract_date_range(sq_data, return = "text"),
|
caption = extract_date_range(sq_data, return = "text"),
|
||||||
bar_colour = "darkblue")
|
bar_colour = "darkblue",
|
||||||
|
rounding = 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
\seealso{
|
\seealso{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче