feat: add percent feature to identify_shifts_wp()

This commit is contained in:
Martin Chan 2021-06-17 17:58:15 +01:00
Родитель 6b47dbe9eb
Коммит 7877b1f712
3 изменённых файлов: 29 добавлений и 11 удалений

Просмотреть файл

@ -110,11 +110,12 @@ create_bar_asis <- function(data,
ggplot(aes(x = reorder(!!sym(group_var), !!sym(bar_var)), y = !!sym(bar_var))) +
geom_col(fill = bar_colour) +
geom_text(aes(label = round(!!sym(bar_var), digits = rounding)),
hjust = -0.25,
color = "#000000",
position = position_stack(vjust = 0.5),
# hjust = -0.25,
color = "#FFFFFF",
fontface = "bold",
size = 4)
} else if(percent == TRUE){
returnPlot <-
data %>%
@ -122,8 +123,9 @@ create_bar_asis <- function(data,
geom_col(fill = bar_colour) +
geom_text(aes(label = scales::percent(!!sym(bar_var),
accuracy = 10 ^ -rounding)),
hjust = -0.25,
color = "#000000",
position = position_stack(vjust = 0.5),
# hjust = -0.25,
color = "#FFFFFF",
fontface = "bold",
size = 4)
@ -138,9 +140,10 @@ create_bar_asis <- function(data,
y = camel_clean(xlab),
x = ylab) +
theme_wpa_basic() +
theme(
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.text.x = element_blank(),
axis.title = element_blank())
theme(
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.text.x = element_blank(),
axis.title = element_blank()
)
}

Просмотреть файл

@ -22,6 +22,9 @@
#'
#' See `Value` for more information.
#'
#' @param percent Logical value to determine whether to show labels as
#' percentage signs. Defaults to `FALSE`.
#'
#' @inheritParams workpatterns_classify_bw
#'
#' @return
@ -54,6 +57,7 @@ identify_shifts_wp <- function(data,
active_threshold = 1,
start_hour = 9,
end_hour = 17,
percent = FALSE,
return = "plot"){
## Remove case-sensitivity for signals
@ -147,6 +151,12 @@ identify_shifts_wp <- function(data,
out_data %>%
group_by(Shifts) %>%
summarise(WeekCount = n()) %>%
{ if(percent == TRUE){
mutate(., WeekCount = WeekCount / sum(WeekCount, na.rm = TRUE))
} else {
.
}
} %>%
arrange(desc(WeekCount)) %>%
utils::head(10) %>%
create_bar_asis(group_var = "Shifts",
@ -155,6 +165,7 @@ identify_shifts_wp <- function(data,
subtitle = "Showing top 10 only",
caption = extract_date_range(data, return = "text"),
ylab = "Shifts",
xlab = "Frequency")
xlab = "Frequency",
percent = percent)
}
}

Просмотреть файл

@ -10,6 +10,7 @@ identify_shifts_wp(
active_threshold = 1,
start_hour = 9,
end_hour = 17,
percent = FALSE,
return = "plot"
)
}
@ -39,6 +40,9 @@ Note that this currently only supports \strong{hourly} increments. If the
official hours specifying checking in and 9 AM and checking out at 5 PM,
then \code{"1700"} should be supplied here.}
\item{percent}{Logical value to determine whether to show labels as
percentage signs. Defaults to \code{FALSE}.}
\item{return}{String specifying what to return. This must be one of the
following strings:
\itemize{