content
stringlengths 0
14.9M
| filename
stringlengths 44
136
|
---|---|
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
#' @title Classify working pattern week archetypes using a rule-based algorithm,
#' using the binary week-based ('bw') method.
#'
#' @description
#' `r lifecycle::badge('experimental')`
#'
#' Apply a rule based algorithm to emails sent by hour of day, using the binary
#' week-based ('bw') method.
#'
#' @author Ainize Cidoncha <ainize.cidoncha@@microsoft.com>
#'
#' @param data A data frame containing email by hours data.
#'
#' @param hrvar A string specifying the HR attribute to cut the data by.
#' Defaults to NULL. This only affects the function when "table" is returned.
#'
#' @param return Character vector to specify what to return.
#' Valid options include:
#' - `"plot"`: returns a grid showing the distribution of archetypes by
#' 'breaks' and number of active hours (default)
#' - `"plot-dist"`: returns a heatmap plot of signal distribution by hour
#' and archetypes
#' - `"data"`: returns the raw data with the classified
#' archetypes
#' - `"table"`: returns a summary table of the archetypes
#' - `"plot-area"`: returns an area plot of the percentages of archetypes
#' shown over time
#' - `"plot-hrvar"`: returns a bar plot showing the count of archetypes,
#' faceted by the supplied HR attribute.
#'
#' @param signals Character vector to specify which collaboration metrics to
#' use:
#' - a combination of signals, such as `c("email", "IM")` (default)
#' - `"email"` for emails only
#' - `"IM"` for Teams messages only
#' - `"unscheduled_calls"` for Unscheduled Calls only
#' - `"meetings"` for Meetings only
#'
#' @param active_threshold A numeric value specifying the minimum number of
#' signals to be greater than in order to qualify as _active_. Defaults to 0.
#'
#' @param start_hour A character vector specifying starting hours, e.g.
#' `"0900"`. Note that this currently only supports **hourly** increments. If
#' the official hours specifying checking in and 9 AM and checking out at 5
#' PM, then `"0900"` should be supplied here.
#' @param end_hour A character vector specifying starting hours, e.g. `"1700"`.
#' Note that this currently only supports **hourly** increments. If the
#' official hours specifying checking in and 9 AM and checking out at 5 PM,
#' then `"1700"` should be supplied here.
#'
#' @param exp_hours Numeric value representing the number of hours the population
#' is expected to be active for throughout the workday. By default, this uses
#' the difference between `end_hour` and `start_hour`.
#'
#' @param mingroup Numeric value setting the privacy threshold / minimum group
#' size. Defaults to 5.
#'
#' @return
#' A different output is returned depending on the value passed to the `return`
#' argument:
#' - `"plot"`: returns a summary grid plot of the classified archetypes
#' (default). A 'ggplot' object.
#' - `"data"`: returns a data frame of the raw data with the classified
#' archetypes
#' - `"table"`: returns a data frame of summary table of the archetypes
#' - `"plot-area"`: returns an area plot of the percentages of archetypes
#' shown over time. A 'ggplot' object.
#' - `"plot-hrvar"`: returns a bar plot showing the count of archetypes,
#' faceted by the supplied HR attribute. A 'ggplot' object.
#'
#' @import ggplot2
#' @importFrom magrittr "%>%"
#' @importFrom data.table ":=" "%like%" "%between%"
#'
#'
#' @family Working Patterns
#'
workpatterns_classify_bw <- function(data,
hrvar = NULL,
signals = c("email","IM"),
start_hour = "0900",
end_hour = "1700",
mingroup = 5,
exp_hours = NULL,
active_threshold = 0,
return = "plot"){
## set up variable -------------------------------------------------------
Active_Hours <- NULL
## Handling NULL values passed to hrvar ----------------------------------
if(is.null(hrvar)){
data <- totals_col(data)
## assign to hrvar_str
## So R doesn't get confused
hrvar_str <- NULL
hrvar_str <- "Total"
} else {
hrvar_str <- hrvar
}
## convert to data.table -------------------------------------------------
data2 <-
data %>%
dplyr::mutate(Date = as.Date(Date, format = "%m/%d/%Y")) %>%
data.table::as.data.table() %>%
data.table::copy()
# Make sure data.table knows we know we're using it
.datatable.aware = TRUE
## Coerce to numeric, remove trailing zeros
start_hour <- as.numeric(gsub(pattern = "00$", replacement = "", x = start_hour))
end_hour <- as.numeric(gsub(pattern = "00$", replacement = "", x = end_hour))
## Total expected hours --------------------------------------------------
## If `NULL`, use the difference between `end_hour` and `start_hour`
if(is.null(exp_hours)){
exp_hours <- end_hour - start_hour
}
## Warning message for extreme values of `exp_hours` ---------------------
if(exp_hours >= 23){
stop(
glue::glue(
"the total working hours is {exp_hours}.
Please provide a valid range."
)
)
} else if(exp_hours >= 12){
message(
glue::glue(
"Note: the total working hours is {exp_hours}.
Output archetypes will be reduced as the total number of hours is greater than or equal to 12."
)
)
} else if(exp_hours <= 3){
message(
glue::glue(
"Note: the total working hours is {exp_hours}.
Output archetypes will be reduced as the total number of hours is fewer than or equal to 3."
)
)
}
## Text replacement only for allowed values ------------------------------
if(any(signals %in% c("email", "IM", "unscheduled_calls", "meetings"))){
signal_set <- gsub(pattern = "email", replacement = "Emails_sent", x = signals) # case-sensitive
signal_set <- gsub(pattern = "IM", replacement = "IMs_sent", x = signal_set)
signal_set <- gsub(pattern = "unscheduled_calls", replacement = "Unscheduled_calls", x = signal_set)
signal_set <- gsub(pattern = "meetings", replacement = "Meetings", x = signal_set)
} else {
stop("Invalid input for `signals`.")
}
## Create 24 summed `Signals_sent` columns -------------------------------
signal_cols <- purrr::map(0:23, ~combine_signals(data, hr = ., signals = signal_set))
signal_cols <- bind_cols(signal_cols)
## Use names for matching
input_var <- names(signal_cols)
## Signals sent by Person and Date
## Data frame with `PersonId`, `Date`, and the 24 signal columns
signals_df <-
data2 %>%
.[, c("PersonId", "Date")] %>%
cbind(signal_cols)
## Signal label
## Only show as `Signals_sent` if more than one signal, i.e. if there is
## aggregation of multiple signals
sig_label <- ifelse(length(signal_set) > 1, "Signals_sent", signal_set)
## Create binary variable 0 or 1 ----------------------------------------
num_cols <- names(which(sapply(signals_df, is.numeric))) # Get numeric columns
signals_df <-
signals_df %>%
data.table::as.data.table() %>%
# active_threshold: minimum signals to qualify as active
.[, (num_cols) := lapply(.SD, function(x) ifelse(x > active_threshold, 1, 0)), .SDcols = num_cols] %>%
.[, ("Active_Hours") := apply(.SD, 1, sum), .SDcols = input_var]
## Classify PersonId-Signal data by time of day --------------------------
## Long format table that classifies each hour of the day on whether it is
## before, within, or after standard hours
WpA_classify <-
signals_df %>%
tidyr::gather(!!sym(sig_label), sent, -PersonId,-Date,-Active_Hours) %>%
data.table::as.data.table()
WpA_classify[, StartEnd := gsub(pattern = "[^[:digit:]]", replacement = "", x = get(sig_label))]
WpA_classify[, Start := as.numeric(substr(StartEnd, start = 1, stop = 2))]
WpA_classify[, End := as.numeric(substr(StartEnd, start = 3, stop = 4))]
WpA_classify[, Before_start := Start < (start_hour)] # Earlier than start hour
WpA_classify[, After_end := End > (end_hour)] # Later than start hour
WpA_classify[, Within_hours := (Start >= start_hour & End <= end_hour)]
WpA_classify[, HourType := NA_character_]
WpA_classify[After_end == TRUE, HourType := "After_end"]
WpA_classify[Before_start == TRUE, HourType := "Before_start"]
WpA_classify[Within_hours == TRUE, HourType := "Within_hours"]
WpA_classify <-
WpA_classify[, c("PersonId", "Date", "Active_Hours", "HourType", "sent")] %>%
.[, .(sent = sum(sent)), by = c("PersonId", "Date", "Active_Hours", "HourType")] %>%
dplyr::as_tibble() %>%
tidyr::spread(HourType, sent) %>%
left_join(WpA_classify %>% ## Calculate first and last activity for day_span
filter(sent > 0)%>%
group_by(PersonId, Date)%>%
summarise(First_signal = min(Start),
Last_signal = max(End)),
by = c("PersonId","Date"))%>%
mutate(Day_Span = Last_signal - First_signal,
Signals_Break_hours = Day_Span - Active_Hours) %>%
data.table::as.data.table()
## Working patterns classification ---------------------------------------
# # Level 1 with 7 personas
# personas_levels <-
# c("0 < 3 hours on",
# "1 Standard with breaks workday",
# "2 Standard continuous workday",
# "3 Standard flexible workday",
# "4 Long flexible workday",
# "5 Long continuous workday",
# "6 Always on (13h+)")
#
# ptn_data_personas <- data.table::copy(WpA_classify)
# ptn_data_personas[, Personas := "Unclassified"]
# ptn_data_personas[Active_Hours > exp_hours & Active_Hours==Day_Span , Personas := "5 Long continuous workday"]
# ptn_data_personas[Active_Hours > exp_hours & Active_Hours<Day_Span, Personas := "4 Long flexible workday"]
# ptn_data_personas[Active_Hours <= exp_hours & (Before_start>0|After_end>0), Personas := "3 Standard flexible workday"] #do we want to split betwen block and non block?
# ptn_data_personas[Active_Hours == exp_hours & Within_hours == exp_hours , Personas := "2 Standard continuous workday"]
# ptn_data_personas[Active_Hours < exp_hours & Before_start==0 & After_end == 0, Personas := "1 Standard with breaks workday"]
# ptn_data_personas[Active_Hours >= 13, Personas := "6 Always on (13h+)"]
# ptn_data_personas[Active_Hours < 3, Personas := "0 < 3 hours on"]
# ptn_data_personas[, Personas := factor(Personas, levels = personas_levels)]
# Level 2 with 8 personas
personas_levels <-
c(
"0 Low Activity (< 3 hours on)",
"1.1 Standard continuous (expected schedule)",
"1.2 Standard continuous (shifted schedule)",
"2.1 Standard flexible (expected schedule)",
"2.2 Standard flexible (shifted schedule)",
"3 Long flexible workday",
"4 Long continuous workday",
"5 Always on (13h+)"
)
ptn_data_personas <- data.table::copy(WpA_classify)
ptn_data_personas[, Personas := "Unclassified"]
ptn_data_personas[Active_Hours > exp_hours & Active_Hours==Day_Span , Personas := "4 Long continuous workday"]
ptn_data_personas[Active_Hours > exp_hours & Active_Hours<Day_Span, Personas := "3 Long flexible workday"]
ptn_data_personas[Active_Hours <= exp_hours & (Before_start>0|After_end>0), Personas := "2.2 Standard flexible (shifted schedule)"]
ptn_data_personas[Active_Hours <= exp_hours & Before_start == 0 & After_end == 0, Personas := "2.1 Standard flexible (expected schedule)"]
ptn_data_personas[Active_Hours == exp_hours & (Before_start > 0 | After_end > 0) & Active_Hours == Day_Span, Personas := "1.2 Standard continuous (shifted schedule)"]
ptn_data_personas[Active_Hours == exp_hours & Before_start == 0 & After_end == 0 & Active_Hours == Day_Span, Personas := "1.1 Standard continuous (expected schedule)"]
ptn_data_personas[Active_Hours >= 13, Personas := "5 Always on (13h+)"]
ptn_data_personas[Active_Hours < 3, Personas := "0 Low Activity (< 3 hours on)"]
ptn_data_personas[, Personas := factor(Personas, levels = personas_levels)]
# bind cut tree to data frame
ptn_data_final <-
ptn_data_personas %>%
left_join(
signals_df %>%
select(-Active_Hours), # Avoid duplication
by = c("PersonId","Date")) %>%
left_join(
data2 %>%
select(PersonId, Date, hrvar_str), # Avoid duplication
by = c("PersonId","Date"))
## Long caption -----------------------------------------------------------
## Parameters used in creating visualization
## Change first character to upper case
firstup <- function(x){
substr(x, start = 1, stop = 1) <- toupper(substr(x, start = 1, stop = 1))
x
}
signals_str <- firstup(paste(signals, collapse = ", "))
cap_long <-
glue::glue(
"Signals used: {signals_str}.
The official hours are {start_hour}:00 and {end_hour}:00, with a total of {exp_hours} expected hours.
\n"
) %>%
paste(extract_date_range(data2, return = "text"))
## Return-chunks ----------------------------------------------------------
return_data <- function(){
dplyr::as_tibble(ptn_data_final) %>%
dplyr::mutate(
Start_hour = start_hour,
End_hour = end_hour,
Exp_hours = exp_hours
)
}
# NOW DEFUNCT - NOT USED ---------------------------------------------------
return_plot <- function(){
## Table for annotation
myTable_legends <-
ptn_data_final %>%
dplyr::as_tibble() %>%
dplyr::group_by(Personas) %>%
dplyr::summarise(WeekCount = n()) %>%
dplyr::ungroup() %>%
dplyr::mutate(WeekPercentage = WeekCount / sum(WeekCount, na.rm = TRUE)) %>%
dplyr::mutate(WeekCount = paste0("n= ", WeekCount, " \n(", scales::percent(WeekPercentage, accuracy = 0.1), ")"))
ptn_data_final %>%
dplyr::as_tibble() %>%
dplyr::select(Personas, dplyr::starts_with(sig_label)) %>%
dplyr::group_by(Personas) %>%
dplyr::summarise_at(vars(dplyr::starts_with(paste0(sig_label, "_"))), ~mean(.)) %>%
purrr::set_names(nm = gsub(pattern = paste0(sig_label, "_"), replacement = "", x = names(.))) %>%
purrr::set_names(nm = gsub(pattern = "_.+", replacement = "", x = names(.))) %>%
tidyr::gather(Hours, Freq, -Personas) %>%
ggplot(aes(x = Hours, y = Personas, fill = Freq)) +
geom_tile(height=.5) +
# geom_text(aes(label = percent(Freq)), size = 3) +
labs(title = "Distribution of Signals by Hour",
subtitle = "Weekly Working Patterns Archetypes") +
scale_fill_continuous(
guide="legend",
low = "white",
high = "#1d627e",
breaks = 0:1,
name="",
labels = c("", "Observed activity")
) +
wpa::theme_wpa_basic() +
ggplot2::annotate("text",
y = myTable_legends$Personas,
x = 26.5,
label = myTable_legends$WeekCount, size = 3) +
ggplot2::annotate("rect",
xmin = 25,
xmax = 28,
ymin = 0.5,
ymax = length(myTable_legends$Personas) + 0.5,
alpha = .2) +
ggplot2::annotate("rect",
xmin = 0.5,
xmax = start_hour + 0.5,
ymin = 0.5,
ymax = 7.5,
alpha = .1,
fill = "gray50") +
ggplot2::annotate("rect",
xmin = end_hour + 0.5,
xmax = 24.5,
ymin = 0.5,
ymax = 7.5,
alpha = .1,
fill = "gray50")
}
# Plot area chart over time -----------------------------------------------
return_plot_area <- function(){
ptn_data_final %>%
dplyr::group_by(Date, Personas) %>%
dplyr::summarise(n = dplyr::n_distinct(PersonId)) %>%
dplyr::mutate(per = n / sum(n)) %>%
dplyr::ungroup() %>%
tidyr::complete(Date, Personas, fill = list(0)) %>%
mutate(per = tidyr::replace_na(per, 0)) %>%
ggplot(aes(x=Date, y=per, fill=Personas)) +
geom_area() +
theme_wpa_basic() +
labs(title = "Distribution of Working Patterns over time",
y = "Percentage",
caption = cap_long) +
theme(legend.position = "right") +
scale_y_continuous(labels = scales::percent)
}
return_table <- function(hrvar = hrvar_str){
if(hrvar == "Total"){
ptn_data_final %>%
data.table::as.data.table() %>%
.[, .(n = .N), by = Personas] %>%
.[, prop := n / sum(n)] %>%
.[] %>%
dplyr::as_tibble() %>%
dplyr::arrange(Personas)
} else {
# Character containing groups above the minimum group threshold
PersonCount <-
ptn_data_final %>%
hrvar_count(hrvar = hrvar, return = "table") %>%
dplyr::filter(n >= mingroup) %>%
dplyr::pull(hrvar) %>%
c("Total") # Ensure included in filter
ptn_data_final %>%
totals_bind(target_col = hrvar, target_value = "Total") %>%
data.table::as.data.table() %>%
.[, .(n = .N), by = c("Personas", hrvar)] %>%
dplyr::as_tibble() %>%
dplyr::filter(!!sym(hrvar) %in% PersonCount) %>%
dplyr::group_by(!!sym(hrvar)) %>%
dplyr::mutate(prop = n / sum(n, na.rm = TRUE)) %>%
dplyr::ungroup() %>%
dplyr::select(-n) %>% # Remove n
tidyr::spread(!!sym(hrvar), prop) %>%
dplyr::arrange(Personas)
}
}
## ReturnR
if(return == "data"){
return_data()
} else if(return == "plot"){
plot_workpatterns_classify_bw(
ptn_data_final,
range = exp_hours,
caption = cap_long
)
} else if(return == "plot-dist"){
return_plot()
} else if(return == "plot-area"){
return_plot_area()
} else if(return == "plot-hrvar"){
plot_wp_bw_hrvar(
x = return_table(),
caption = cap_long
)
} else if (return == "table"){
return_table()
} else if (return == "list"){
list(data = return_data(),
plot = plot_workpatterns_classify_bw(
ptn_data_final,
range = exp_hours,
caption = cap_long
),
plot_hrvar = plot_wp_bw_hrvar(
x = return_table(),
caption = cap_long
),
plot_area = return_plot_area(),
table = return_table())
} else {
stop("Invalid input for `return`.")
}
}
#' @title Plotting function for `workpatterns_classify_bw()`
#'
#' @description Internal use only.
#'
#' @param range Numeric. Accepts `exp_hours` from the main `workpatterns_classify_bw()`
#' function. Used to update labels on main plot.
#' @param caption String to override plot captions.
#'
#' @noRd
plot_workpatterns_classify_bw <- function(data, range, caption){
plot_table <-
data %>%
dplyr::mutate(
PersonasNet =
case_when(
Personas == "0 Low Activity (< 3 hours on)" ~ "Low activity",
Personas == "2.1 Standard flexible (expected schedule)" ~ "Flexible",
Personas == "2.2 Standard flexible (shifted schedule)" ~ "Flexible",
Personas == "1.1 Standard continuous (expected schedule)" ~ "Standard",
Personas == "1.2 Standard continuous (shifted schedule)" ~ "Standard",
Personas == "3 Long flexible workday" ~ "Long flexible",
Personas == "4 Long continuous workday" ~ "Long continuous",
Personas == "5 Always on (13h+)" ~ "Always On",
TRUE ~ NA_character_
)
) %>%
dplyr::count(PersonasNet) %>%
dplyr::mutate(Percent = n / sum(n, na.rm = TRUE))
# Create base plot ----------------------------------------------------------
base_df <-
dplyr::tibble(id = 1:6,
value = c("Always On",
"Long continuous",
"Long flexible",
"Standard",
"Flexible",
"Low activity"),
text = c(rep("#FFFFFF", 3),
rep("grey5", 3)),
fill = c(
rgb2hex(50, 83, 105),
rgb2hex(69, 113, 138),
rgb2hex(65, 150, 168),
rgb2hex(175, 175, 175),
rgb2hex(114, 194, 217),
rgb2hex(221, 221, 221)
))
flexibility <-
c(0, 0, 4, 4, # Always On
0, 0, 2, 2, # Long (non-stop)
2, 2, 4, 4, # Long with breaks
0, 0, 2, 2, # Standard (non-stop)
2, 2, 4, 4, # Standard flexible
0, 0, 4, 4) # Low activity
act_level <-
c(6, 8, 8, 6, # Always On
4, 6, 6, 4, # Long (non-stop)
4, 6, 6, 4, # Long with breaks
2, 4, 4, 2, # Standard (non-stop)
2, 4, 4, 2, # Standard flexible
0, 2, 2, 0) # Low activity
main_plot_df <-
rbind(base_df,
base_df,
base_df,
base_df) %>%
arrange(id) %>%
mutate(Flexibility = flexibility,
ActivityLevel = act_level)
label_df <-
main_plot_df %>%
group_by(id, value) %>%
# Get mid-points of coordinates
summarise(flexibility = mean(Flexibility),
act_level = mean(ActivityLevel),
.groups = "drop") %>%
left_join(
plot_table,
by = c("value" = "PersonasNet")
) %>%
# Get colours and fill back into the data
left_join(
base_df,
by = c("id", "value")
) %>%
mutate(value2 = sub(" ", "\n", value)# ,
# text = ifelse(id %in% c(1, 2, 5, 6),"#FFFFFF", "black"),
# fill = ifelse(id %in% c(1, 2, 5, 6),"#1d627e", "#34b1e2")
) %>%
mutate(Percent = paste(round(Percent * 100), "%")) %>%
mutate(Percent = ifelse(is.na(Percent), "0 %", Percent)) %>%
mutate(value2 = paste(value2, Percent, sep = "\n"))
colo_v <- setNames(base_df$fill, nm = base_df$value)
text_v <- setNames(base_df$text, nm = base_df$value)
## UNCOMMENT TO DEBUG
# list(
# base_df,
# colo_v,
# text_v,
# main_plot_df,
# label_df
# ) %>%
# print()
# Vertical labels conditional --------------------------------------------
if(range <= 12){
v_labels <-
c("",
"< 3 hours",
"",
glue::glue("3 - {range} hours"),
"",
glue::glue("{range + 1} - 12 hours"),
"",
"13+ hours",
""
)
} else {
v_labels <-
c("",
"< 3 hours",
"",
glue::glue("3 - {range} hours"),
"",
"",
"",
glue::glue("{range}+ hours"),
""
)
}
main_plot_df %>%
ggplot(aes(x = Flexibility, y = ActivityLevel)) +
geom_polygon(
aes(fill = value,
group = id),
colour = "#FFFFFF",
size = 2) +
scale_fill_manual(values = colo_v) +
geom_text(data = label_df,
aes(x = flexibility,
y = act_level,
label = value2,
colour = value),
size = 5) +
scale_colour_manual(values = text_v) +
scale_y_continuous(breaks = 0:8,
labels = v_labels) +
scale_x_continuous(breaks = 0:4,
labels = c("", "No quiet hours", "",
"Take quiet hours", "")) +
labs(title = "Distribution of Working Patterns",
subtitle = "Classification of employee-weeks",
x = "Flexibility level (breaks)",
y = "Average activity level",
caption = caption) +
theme_wpa_basic() +
theme(
legend.position = "none",
axis.line = element_blank(),
axis.title = element_blank() # Toggle off axis title
)
}
#' @title
#' Plotting a faceted bar plot for `workpatterns_classify_bw()`
#'
#' @description Internal use only.
#'
#' @details
#' Accepts a `"table"` input.
#'
#' @import ggplot2
#'
#' @noRd
plot_wp_bw_hrvar <- function(x, caption){
x %>%
tidyr::pivot_longer(cols = -Personas) %>%
ggplot(aes(x = Personas,
y = value)) +
geom_col(fill = "lightblue") +
facet_wrap(. ~ name) +
geom_text(aes(label = scales::percent(value, accuracy = 1)),
size = 3,
hjust = -0.3) +
coord_flip() +
scale_y_continuous(labels = scales::percent,
limits = c(NA, 1)) +
theme_wpa_basic() +
labs(caption = caption)
}
|
/scratch/gouwar.j/cran-all/cranData/wpa/R/workpatterns_classify_bw.R
|
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
#' @title Classify working pattern personas using a rule based algorithm, using
#' the person-average volume-based ('pav') method.
#'
#' @description
#' `r lifecycle::badge('experimental')`
#'
#' Apply a rule based algorithm to emails or instant messages sent by hour of day.
#' This uses a person-average volume-based ('pav') method.
#'
#' @author Ainize Cidoncha <ainize.cidoncha@@microsoft.com>
#'
#' @param data A data frame containing data from the Hourly Collaboration query.
#'
#' @param return Character vector to specify what to return. Valid options include:
#' - `"plot"`: returns a bar plot of signal distribution by hour and archetypes (default)
#' - `"data"`: returns the raw data with the classified archetypes
#' - `"table"`: returns a summary table of the archetypes
#' - `"plot-area"`: returns an overlapping area plot
#'
#' @param values Character vector to specify whether to return percentages
#' or absolute values in "data" and "plot". Valid values are:
#' - "percent": percentage of signals divided by total signals (default)
#' - "abs": absolute count of signals
#'
#' @param signals Character vector to specify which collaboration metrics to use:
#' - "email" (default) for emails only
#' - "IM" for Teams messages only,
#' - "unscheduled_calls" for Unscheduled Calls only
#' - "meetings" for Meetings only
#' - or a combination of signals, such as `c("email", "IM")`
#'
#' @param start_hour A character vector specifying starting hours,
#' e.g. "0900"
#' @param end_hour A character vector specifying starting hours,
#' e.g. "1700"
#'
#' @return
#' A different output is returned depending on the value passed to the `return`
#' argument:
#' - `"plot"`: returns a bar plot of signal distribution by hour and
#' archetypes (default). A 'ggplot' object.
#' - `"data"`: returns a data frame of the raw data with the classified archetypes.
#' - `"table"`: returns a data frame of a summary table of the archetypes.
#' - `"plot-area"`: returns an overlapping area plot. A 'ggplot' object.
#'
#' @import dplyr
#' @import tidyselect
#' @import ggplot2
#'
#' @family Working Patterns
#'
workpatterns_classify_pav <- function(data,
values = "percent",
signals = c("email", "IM"),
start_hour = "0900",
end_hour = "1700",
return = "plot"){
## Coerce to numeric
start_hour <- as.numeric(sub(pattern = "00$", replacement = "", x = start_hour))
end_hour <- as.numeric(sub(pattern = "00$", replacement = "", x = end_hour))
# Text replacement only for allowed values
if(any(signals %in% c("email", "IM", "unscheduled_calls", "meetings"))){
signal_set <- gsub(pattern = "email", replacement = "Emails_sent", x = signals) # case-sensitive
signal_set <- gsub(pattern = "IM", replacement = "IMs_sent", x = signal_set)
signal_set <- gsub(pattern = "unscheduled_calls", replacement = "Unscheduled_calls", x = signal_set)
signal_set <- gsub(pattern = "meetings", replacement = "Meetings", x = signal_set)
} else {
stop("Invalid input for `signals`.")
}
## Create 24 summed `Signals_sent` columns
signal_cols <- purrr::map(0:23, ~combine_signals(data, hr = ., signals = signal_set))
signal_cols <- bind_cols(signal_cols)
## Use names for matching
input_var <- names(signal_cols)
## Average signals sent by Person
signals_df <-
data %>%
select(PersonId) %>%
cbind(signal_cols) %>%
group_by(PersonId) %>%
summarise_all(~mean(.))
## Signal label
sig_label <- ifelse(length(signal_set) > 1, "Signals_sent", signal_set)
## Normalised pattern data
ptn_data_norm <-
signals_df %>%
mutate(Signals_Total = select(., all_of(input_var)) %>% apply(1, sum)) %>%
mutate_at(vars(all_of(input_var)), ~./Signals_Total) %>%
#filter(Signals_Total > 0) %>%
select(all_of(input_var)) %>%
mutate(across(where(is.numeric), ~tidyr::replace_na(., 0))) # Replace NAs with 0s
## Normalised pattern data
ptn_data_norm <-
signals_df %>%
mutate(Signals_Total = select(., all_of(input_var)) %>% apply(1, sum)) %>%
mutate_at(vars(all_of(input_var)), ~./Signals_Total) %>%
#filter(Signals_Total > 0) %>%
select(PersonId,Signals_Total, all_of(input_var)) %>%
mutate_at(vars(all_of(input_var)), # Replace NAs with 0s
~tidyr::replace_na(., 0))
## Classify PersonId-Signal data by time of day
ptn_data_classify <-
ptn_data_norm %>%
tidyr::gather(Signals_sent, Prop, -PersonId,-Signals_Total) %>%
mutate(StartEnd = gsub(pattern = "[^[:digit:]]", replacement = "", x = Signals_sent),
Start = as.numeric(substr(StartEnd, start = 1, stop = 2)),
End = as.numeric(substr(StartEnd, start = 3, stop = 4))) %>%
mutate(Before_start = (Start < start_hour)) %>% # Earlier than working hours
mutate(After_end = (End > end_hour)) %>% # Later than working hours
mutate(Within_hours = (Start >= start_hour & End <= end_hour)) %>%
mutate(HourType = case_when(Before_start == TRUE ~ "Before_start",
After_end == TRUE ~ "After_end",
Within_hours == TRUE ~ "Within_hours",
TRUE ~ NA_character_)) %>%
select(PersonId, HourType, Signals_Total, Prop) %>%
group_by(PersonId,Signals_Total, HourType) %>%
summarise(Prop = sum(Prop)) %>%
tidyr::spread(HourType, Prop) %>%
ungroup()
ptn_data_personas <-
ptn_data_classify %>%
mutate(Personas =
case_when(Signals_Total<10~ "Absent",
Before_start >= .15 & Within_hours < 0.70 & After_end < 0.15 ~ "Extended Hours\n- Morning",
Before_start < 0.15 & Within_hours < 0.70 & After_end >= 0.15 ~ "Extended Hours\n- Evening",
Within_hours < 0.3 ~ "Overnight workers",
Within_hours >= .7 ~ "Standard Hours",
Before_start >= 0.15 & Within_hours < 0.70 & After_end >= 0.15 ~ "Always On",
TRUE ~ "Unclassified"))
## Percentage vs Absolutes
if(values == "percent"){
# bind cut tree to data frame
ptn_data_final <-
ptn_data_personas %>%
left_join(ptn_data_norm, by = "PersonId")
} else if(values == "abs"){
ptn_data_final <-
ptn_data_personas %>%
left_join(signals_df, by = "PersonId")
} else {
stop("Invalid `values` input. Please either input 'percent' or 'abs'.")
}
## Return
if(return == "data"){
return(ptn_data_final)
} else if(return == "plot"){
plot <-
plot_signal_clust(ptn_data_final,
group_label = "Personas",
type = "bar",
sig_label = sig_label)
return(plot)
} else if(return == "plot-area"){
plot <-
plot_signal_clust(ptn_data_final,
group_label = "Personas",
type = "area",
sig_label = sig_label)
return(plot)
} else if (return == "table"){
## Count table
count_tb <-
ptn_data_final %>%
group_by(Personas) %>%
summarise(n = n()) %>%
mutate(prop = n / sum(n))
## Summary statistics
sums_tb <-
ptn_data_final %>%
run_sum_hr(group_label = "Personas",
sig_label = sig_label)
## Time slots
times_tb <-
ptn_data_final %>%
run_hour_splits(start_hour = start_hour,
end_hour = end_hour,
group_label = "Personas")
count_tb %>%
left_join(sums_tb, by = "Personas") %>%
left_join(times_tb, by = "Personas") %>%
return()
} else {
stop("Invalid input for `return`.")
}
}
|
/scratch/gouwar.j/cran-all/cranData/wpa/R/workpatterns_classify_pav.R
|
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
#' @title Create a hierarchical clustering of email or IMs by hour of day
#'
#' @description
#' `r lifecycle::badge('experimental')`
#'
#' Apply hierarchical clustering to emails sent by hour of day.
#' The hierarchical clustering uses cosine distance and the ward.D method
#' of agglomeration.
#'
#' @details
#' The hierarchical clustering is applied on the person-average volume-based (pav) level.
#' In other words, the clustering is applied on a dataset where the collaboration hours
#' are averaged by person and calculated as % of total daily collaboration.
#'
#' @param data A data frame containing data from the Hourly Collaboration query.
#' @param k Numeric vector to specify the `k` number of clusters to cut by.
#'
#' @param return String specifying what to return. This must be one of the
#' following strings:
#' - `"plot"`
#' - `"data"`
#' - `"table"`
#' - `"plot-area"`
#' - `"hclust"`
#' - `"dist"`
#'
#' See `Value` for more information.
#'
#' @param values Character vector to specify whether to return percentages
#' or absolute values in "data" and "plot". Valid values are:
#' - "percent": percentage of signals divided by total signals (default)
#' - "abs": absolute count of signals
#'
#' @param signals Character vector to specify which collaboration metrics to use:
#' - `"email"` (default) for emails only
#' - `"IM"` for Teams messages only
#' - `"unscheduled_calls"` for Unscheduled Calls only
#' - `"meetings"` for Meetings only
#' - or a combination of signals, such as `c("email", "IM")`
#' @param start_hour A character vector specifying starting hours,
#' e.g. "0900"
#' @param end_hour A character vector specifying starting hours,
#' e.g. "1700"
#'
#' @return
#' A different output is returned depending on the value passed to the `return`
#' argument:
#' - `"plot"`: ggplot object of a bar plot (default)
#' - `"data"`: data frame containing raw data with the clusters
#' - `"table"`: data frame containing a summary table. Percentages of signals
#' are shown, e.g. x% of signals are sent by y hour of the day.
#' - `"plot-area"`: ggplot object. An overlapping area plot
#' - `"hclust"`: `hclust` object for the hierarchical model
#' - `"dist"`: distance matrix used to build the clustering model
#'
#' @import dplyr
#' @import tidyselect
#' @import ggplot2
#' @importFrom proxy dist
#' @importFrom stats hclust
#' @importFrom stats rect.hclust
#' @importFrom stats cutree
#' @importFrom tidyr replace_na
#'
#' @examples
#' \donttest{
#' # Run clusters, returning plot
#' workpatterns_hclust(em_data, k = 5, return = "plot")
#'
#' # Run clusters, return raw data
#' workpatterns_hclust(em_data, k = 4, return = "data") %>% head()
#'
#' # Run clusters for instant messages only, return hclust object
#' workpatterns_hclust(em_data, k = 4, return = "hclust", signals = c("IM"))
#' }
#'
#' @family Clustering
#' @family Working Patterns
#'
#' @export
workpatterns_hclust <- function(data,
k = 4,
return = "plot",
values = "percent",
signals = "email",
start_hour = "0900",
end_hour = "1700"){
# Text replacement only for allowed values
if(any(signals %in% c("email", "IM", "unscheduled_calls", "meetings"))){
signal_set <- gsub(pattern = "email", replacement = "Emails_sent", x = signals) # case-sensitive
signal_set <- gsub(pattern = "IM", replacement = "IMs_sent", x = signal_set)
signal_set <- gsub(pattern = "unscheduled_calls", replacement = "Unscheduled_calls", x = signal_set)
signal_set <- gsub(pattern = "meetings", replacement = "Meetings", x = signal_set)
} else {
stop("Invalid input for `signals`.")
}
## Create 24 summed `Signals_sent` columns
signal_cols <- purrr::map(0:23, ~combine_signals(data, hr = ., signals = signal_set))
signal_cols <- bind_cols(signal_cols)
## Use names for matching
input_var <- names(signal_cols)
## Average signals sent by Person
signals_df <-
data %>%
select(PersonId) %>%
cbind(signal_cols) %>%
group_by(PersonId) %>%
summarise_all(~mean(.))
## Signal label
sig_label <- ifelse(length(signal_set) > 1, "Signals_sent", signal_set)
## Normalised pattern data
ptn_data_norm <-
signals_df %>%
mutate(Signals_Total = select(., all_of(input_var)) %>% apply(1, sum)) %>%
mutate_at(vars(input_var), ~./Signals_Total) %>%
filter(Signals_Total > 0) %>%
select(PersonId, all_of(input_var)) %>%
mutate(across(where(is.numeric), ~tidyr::replace_na(., 0))) # Replace NAs with 0s
## Distance matrix
dist_m <-
ptn_data_norm %>%
select(all_of(input_var)) %>%
proxy::dist(method = "cosine")
## Run hclust
h_clust <-
dist_m %>%
stats::hclust(method = "ward.D")
## Cut tree
cuts <- stats::cutree(h_clust, k = k)
# Percentage vs Absolutes
if(values == "percent"){
# bind cut tree to data frame
ptn_data_final <- cbind(ptn_data_norm, "cluster" = cuts)
} else if(values == "abs"){
ptn_data_final <-
ptn_data_norm %>%
select(PersonId) %>%
cbind("cluster" = cuts) %>%
left_join(signals_df, by = "PersonId")
} else {
stop("Invalid `values` input. Please either input 'percent' or 'abs'.")
}
## Return
if(return == "data"){
return(ptn_data_final)
} else if(return == "plot"){
plot <-
plot_signal_clust(ptn_data_final,
group_label = "cluster",
type = "bar",
sig_label = sig_label)
return(plot)
} else if(return == "plot-area"){
plot <-
plot_signal_clust(ptn_data_final,
group_label = "cluster",
type = "area",
sig_label = sig_label)
return(plot)
} else if(return == "table"){
## Count table
count_tb <-
ptn_data_final %>%
group_by(cluster) %>%
summarise(n = n()) %>%
mutate(prop = n / sum(n))
## Summary statistics
sums_tb <-
ptn_data_final %>%
run_sum_hr(sig_label = sig_label)
## Time slots
times_tb <-
ptn_data_final %>%
run_hour_splits(start_hour = start_hour,
end_hour = end_hour,
group_label = "cluster")
count_tb %>%
left_join(sums_tb, by = "cluster") %>%
left_join(times_tb, by = "cluster") %>%
return()
} else if(return == "hclust"){
return(h_clust)
} else if(return == "dist"){
return(dist_m)
} else {
stop("Invalid input for `return`.")
}
}
#' @title Plot signal hour patterns by clusters
#'
#' @description Workhorse function feeding into `workpatterns_hclust()`.
#' This is a build on `plot_email_clust` to allow flexible inputs.
#'
#' @param data Data frame containing the normalised email by hour
#' data and the cluster variable
#'
#' @param group_label Character vector specifying the name of the variable
#' containing the clusters.
#'
#' @param type Character vector to specify type of plot to return.
#' Accepted values are "bar" (default) and "area".
#'
#' @param sig_label Character vector to select required columns,
#' e.g. "Emails_sent", "IMs_sent", "Signals_sent"
#'
#' @import ggplot2
#' @import dplyr
#' @importFrom tidyselect all_of
#' @importFrom tidyr gather
#'
#' @noRd
plot_signal_clust <- function(data,
group_label,
type = "bar",
sig_label = "Emails_sent"){
metric_label <- sub(pattern = "_sent", replacement = "", x = sig_label)
## Maximum value
max_val <-
data %>%
select(starts_with(sig_label)) %>%
gather(key, value) %>%
pull(value) %>%
max()
## Absolute vs Percent
abs_true <-
ifelse(max_val > 1, TRUE, FALSE)
## Create labels for n
ptn_data_n <-
data %>%
rename(clusters = tidyselect::all_of(group_label)) %>%
count(clusters) %>%
mutate(label = paste0(clusters, "\n\n", "n=",n))
## Create plotting data
plot_data <-
data %>%
rename(clusters = tidyselect::all_of(group_label)) %>%
select(clusters, starts_with(sig_label)) %>%
group_by(clusters) %>%
summarise_at(vars(starts_with(sig_label)), ~mean(.)) %>%
tidyr::gather(Hours, !!sym(sig_label), -clusters) %>%
left_join(ptn_data_n %>% select(clusters, label),
by = "clusters") %>%
mutate_at("Hours", ~sub(pattern = paste0(sig_label, "_"), replacement = "", x = .)) %>%
mutate_at("Hours", ~sub(pattern = "_.+", replacement = "", x = .))
## bar plot
output_bar <-
plot_data %>%
ggplot(aes(x = Hours, y = !!sym(sig_label))) +
geom_col(fill = "#2d7a8a") +
theme_minimal() +
{if (abs_true)
scale_y_continuous(labels = round)
else
scale_y_continuous(labels = scales::percent)
} +
theme_wpa_basic() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
facet_grid(label~.) +
ggtitle(label = paste("Distribution of", metric_label, "by Hour"),
subtitle = group_label) +
{if (abs_true) ylab(paste(metric_label, "sent (absolute)"))
else ylab(paste(metric_label, "sent (percentage of daily total"))
}
## overlapping area plot
output_area <-
plot_data %>%
mutate_at("Hours", ~as.numeric(.)) %>%
mutate_at("clusters", ~as.factor(.)) %>%
ggplot(aes(x = Hours, y = !!sym(sig_label), colour = clusters)) +
geom_line(size = 1) +
geom_area(aes(fill = clusters), alpha = 0.2, position = 'identity') +
theme_wpa_basic() +
scale_x_continuous(labels = pad2) +
scale_y_continuous(labels = round) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
ggtitle(label = paste("Distribution of", metric_label, "by Hour"),
subtitle = group_label) +
{if (abs_true) ylab(paste(metric_label, "sent (absolute)"))
else ylab(paste(metric_label, "sent (percentage of daily total)"))
}
if(type == "bar"){
return(output_bar)
} else if(type == "area"){
return(output_area)
} else {
stop("Invalid `type` input.")
}
}
#' @title Run summary statistics for hours of day
#'
#' @description
#' Supporting function that takes the raw data from `workpatterns_hclust()`
#' as an input.
#'
#'
#' @import dplyr
#' @param data See `workpatterns_hclust()`.
#' @param group_label A character vector for the column name containing the clusters
#' or the groups. Currently accepted values are "cluster" and "Personas".
#' @param sig_label See `workpatterns_hclust()`.
#'
#' @noRd
run_sum_hr <- function(data,
group_label = "cluster",
sig_label = "Emails_sent"){
data %>%
rename(cluster = tidyselect::all_of(group_label)) %>%
group_by(cluster) %>%
summarise_at(vars(starts_with(sig_label)), ~mean(.)) %>%
tidyr::gather(Signals, prop, -cluster) %>%
arrange(-prop) %>%
mutate(Hours = gsub(pattern = "[^[:digit:]{2}]", replacement = "", x = Signals)) %>%
mutate(Hours = substr(Hours, start = 1, stop = 2)) %>%
mutate(Hours = as.numeric(Hours)) %>%
select(cluster, prop, Hours) %>%
dplyr::group_split(cluster) %>%
purrr::map(function(x){
hour_raw <-
x %>%
mutate_at("prop", ~.*1000) %>%
with(rep(Hours, prop))
## Unique values of hour_raw
uni <- unique(hour_raw)
## Mode
mode_val <- uni[which.max(tabulate(match(hour_raw, uni)))]
dplyr::tibble(cluster = x$cluster[1],
median_hour = median(hour_raw),
p5_hour = stats::quantile(hour_raw, .05),
p25_hour = stats::quantile(hour_raw, .25),
p75_hour = stats::quantile(hour_raw, .75),
p95_hour = stats::quantile(hour_raw, .95),
mode_hour = mode_val,
sd_hour = sd(hour_raw),
mean_hour = mean(hour_raw))
}) %>%
dplyr::bind_rows() %>%
rename(!!sym(group_label) := "cluster") %>%
return()
}
#' @title Run working hour splits for signals sent
#'
#' @description
#' Used internally within `workpatterns_hclust()`
#'
#' @import dplyr
#'
#' @param data See `workpatterns_hclust()`.
#' @param start_hour See `workpatterns_hclust()`.
#' @param end_hour See `workpatterns_hclust()`.
#' @param group_label See `workpatterns_hclust()`.
#'
#' @noRd
run_hour_splits <- function(data,
start_hour = "0900",
end_hour = "1700",
group_label = "cluster"){
## Coerce to numeric
start_hour <- as.numeric(sub(pattern = "00$", replacement = "", x = start_hour))
end_hour <- as.numeric(sub(pattern = "00$", replacement = "", x = end_hour))
data %>%
rename(cluster = tidyselect::all_of(group_label)) %>%
tidyr::gather(Signals, Prop, -PersonId, -cluster) %>%
mutate(StartEnd = gsub(pattern = "[^[:digit:]]", replacement = "", x = Signals),
Start = as.numeric(substr(StartEnd, start = 1, stop = 2)),
End = as.numeric(substr(StartEnd, start = 3, stop = 4))) %>%
mutate(Before_start = (Start < start_hour)) %>% # Earlier than working hours
mutate(After_end = (End > end_hour)) %>% # Later than working hours
mutate(Within_hours = (Start >= start_hour & End <= end_hour)) %>%
mutate(HourType = case_when(Before_start == TRUE ~ "Before_start",
After_end == TRUE ~ "After_end",
Within_hours == TRUE ~ "Within_hours",
TRUE ~ NA_character_)) %>%
select(PersonId, HourType, Prop, cluster) %>%
group_by(cluster, PersonId, HourType) %>%
summarise(Prop = sum(Prop)) %>%
tidyr::spread(HourType, Prop) %>%
ungroup() %>%
group_by(cluster) %>%
summarise_at(vars(Before_start, Within_hours, After_end),
~mean(.)) %>%
rename(!!sym(group_label) := "cluster") %>%
return()
}
|
/scratch/gouwar.j/cran-all/cranData/wpa/R/workpatterns_hclust.R
|
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
#' @title Create a rank table of working patterns
#'
#' @description
#' Takes in an Hourly Collaboration query and returns a count
#' table of working patterns, ranked from the most common to the
#' least.
#'
#' @param data A data frame containing hourly collaboration data.
#' @param signals Character vector to specify which collaboration metrics to
#' use:
#' - `"email"` (default) for emails only
#' - `"IM"` for Teams messages only
#' - `"unscheduled_calls"` for Unscheduled Calls only
#' - `"meetings"` for Meetings only
#' - or a combination of signals, such as `c("email", "IM")`
#' @param start_hour A character vector specifying starting hours,
#' e.g. "`0900"`
#' @param end_hour A character vector specifying starting hours,
#' e.g. `"1700"`
#' @param top numeric value specifying how many top working patterns to display in plot,
#' e.g. `"10"`
#'
#' @param mode string specifying aggregation method for plot. Valid
#' options include:
#' - `"binary"`: convert hourly activity into binary blocks. In the plot, each
#' block would display as solid.
#' - `"prop"`: calculate proportion of signals in each hour over total signals
#' across 24 hours, then average across all work weeks. In the plot, each
#' block would display as a heatmap.
#'
#' @param return String specifying what to return. This must be one of the
#' following strings:
#' - `"plot"`
#' - `"table"`
#'
#' See `Value` for more information.
#' @return
#' A different output is returned depending on the value passed to the `return`
#' argument:
#' - `"plot"`: ggplot object. A plot with the y-axis showing the top ten
#' working patterns and the x-axis representing each hour of the day.
#' - `"table"`: data frame. A summary table for the top working patterns.
#'
#' @importFrom data.table ":=" "%like%" "%between%"
#'
#' @examples
#' \donttest{
#' # Plot by default
#' workpatterns_rank(
#' data = em_data,
#' signals = c(
#' "email",
#' "IM",
#' "unscheduled_calls",
#' "meetings"
#' )
#' )
#'
#' # Plot with prop / heatmap mode
#' workpatterns_rank(
#' data = em_data,
#' mode = "prop"
#' )
#' }
#'
#' @family Visualization
#' @family Working Patterns
#'
#' @export
workpatterns_rank <- function(data,
signals = c("email", "IM"),
start_hour = "0900",
end_hour = "1700",
top = 10,
mode = "binary",
return = "plot"){
# Make sure data.table knows we know we're using it
.datatable.aware = TRUE
## Save original
start_hour_o <- start_hour
end_hour_o <- end_hour
## Coerce to numeric, remove trailing zeros
start_hour <- as.numeric(gsub(pattern = "00$", replacement = "", x = start_hour))
end_hour <- as.numeric(gsub(pattern = "00$", replacement = "", x = end_hour))
## convert to data.table
data2 <-
data %>%
dplyr::mutate(Date = as.Date(Date, format = "%m/%d/%Y")) %>%
data.table::as.data.table() %>%
data.table::copy()
## Dynamic input for signals
## Text replacement only for allowed values
if(any(signals %in% c("email", "IM", "unscheduled_calls", "meetings"))){
signal_set <- gsub(pattern = "email", replacement = "Emails_sent", x = signals) # case-sensitive
signal_set <- gsub(pattern = "IM", replacement = "IMs_sent", x = signal_set)
signal_set <- gsub(pattern = "unscheduled_calls", replacement = "Unscheduled_calls", x = signal_set)
signal_set <- gsub(pattern = "meetings", replacement = "Meetings", x = signal_set)
## Create label for plot subtitle
subtitle_signal <- "signals" # placeholder
} else {
stop("Invalid input for `signals`.")
}
## Create 24 summed `Signals_sent` columns
signal_cols <- purrr::map(0:23, ~combine_signals(data, hr = ., signals = signal_set))
signal_cols <- bind_cols(signal_cols)
## Use names for matching
input_var <- names(signal_cols)
## Signals sent by Person and Date
signals_df <-
data2 %>%
.[, c("PersonId", "Date")] %>%
cbind(signal_cols)
## Signal label
sig_label <- ifelse(length(signal_set) > 1, "Signals_sent", signal_set)
## This should only pick up `Signals_sent_` prefixed columns
## This is run on `signals_df`
num_cols <- names(which(sapply(signals_df, is.numeric))) # Get numeric columns
if(mode == "binary"){
## Summarized table performed on `signals_df` ----------------------------
## Section ignoring `signals_df_o`
signals_df <-
signals_df %>%
data.table::as.data.table() %>%
.[, (num_cols) := lapply(.SD, function(x) ifelse(x > 0, 1, 0)), .SDcols = num_cols] %>%
.[, list(WeekCount = .N, PersonCount = dplyr::n_distinct(PersonId)), by = input_var]
myTable_return <- data.table::setorder(signals_df, -PersonCount)
} else if(mode == "prop"){
## Save original `signals_df` before manipulating ------------------------
## Rename `Signals_sent` columns to prevent conflict
signals_df_o <- signals_df %>%
purrr::set_names(
nm = gsub(x = names(.),
replacement = "_ori_",
pattern = "_sent_")
) %>%
cbind(select(signals_df, num_cols)) %>% # duplicate signals
# Convert `Signals_sent_` prefixed to binary. `Signals_ori_` are intact
# Create binary variable 0 or 1
.[, (num_cols) := lapply(.SD, function(x) ifelse(x > 0, 1, 0)), .SDcols = num_cols] %>%
# Use `mutate()` method
.[, `:=`(WeekCount = .N,
PersonCount = dplyr::n_distinct(PersonId),
Id = .GRP), # group id assignment
by = num_cols]
## 00, 01, 02, etc.
hours_col <- pad2(x = seq(0,23))
# Wide table showing proportion of signals by hour
# Ranked descending by `WeekCount`
wp_prop_tb <-
signals_df_o %>%
arrange(desc(WeekCount)) %>%
dplyr::select(Id, dplyr::contains("_ori_"), WeekCount) %>%
purrr::set_names(nm = gsub(
pattern = ".+_ori_",
replacement = "",
x = names(.)
)) %>%
purrr::set_names(nm = gsub(
pattern = "_.+",
replacement = "",
x = names(.)
)) %>%
# Need aggregation
.[, Signals_Total := rowSums(.SD), .SDcols = hours_col] %>%
.[, c(hours_col) := .SD / Signals_Total, .SDcols = hours_col] %>%
.[, Signals_Total := NULL] %>% # Remove unneeded column
.[, lapply(.SD, mean, na.rm = TRUE), .SDcols = hours_col, by = list(Id, WeekCount)]
} else {
stop("invalid value to `mode`.")
}
if(return == "plot" & mode == "binary"){
## Plot return
sig_label_ <- paste0(sig_label, "_")
myTable_return <-
myTable_return %>%
arrange(desc(WeekCount)) %>%
mutate(patternRank= 1:nrow(.))
## Table for annotation
myTable_legends <-
myTable_return %>%
dplyr::select(patternRank, WeekCount) %>%
dplyr::mutate(WeekPercentage = WeekCount / sum(WeekCount, na.rm = TRUE),
WeekCount = paste0(scales::percent(WeekPercentage, accuracy = 0.1))) %>%
utils::head(top)
coverage <-
myTable_legends %>%
summarize(total = sum(WeekPercentage)) %>%
pull(1) %>%
scales::percent(accuracy = 0.1)
myTable_return %>%
dplyr::select(patternRank, dplyr::starts_with(sig_label_)) %>%
purrr::set_names(nm = gsub(
pattern = sig_label_,
replacement = "",
x = names(.)
)) %>%
purrr::set_names(nm = gsub(
pattern = "_.+",
replacement = "",
x = names(.)
)) %>%
plot_hourly_pat(
start_hour = start_hour,
end_hour = end_hour,
legend = myTable_legends,
legend_label = "WeekCount",
legend_text = paste("Observed", subtitle_signal, "activity"),
rows = top,
title = "Patterns of digital activity",
subtitle = paste(
"Hourly activity based on",
subtitle_signal,
"sent over a week"),
caption = paste(
"Top",
top,
"patterns represent",
coverage,
"of workweeks.\n",
extract_date_range(data, return = "text")
),
ylab = paste("Top", top, "activity patterns")
)
} else if(return == "plot" & mode == "prop"){
## Table for annotation
myTable_legends <-
wp_prop_tb %>%
arrange(desc(WeekCount)) %>%
mutate(patternRank= 1:nrow(.)) %>%
dplyr::select(patternRank, WeekCount) %>%
dplyr::mutate(WeekPercentage = WeekCount / sum(WeekCount, na.rm = TRUE),
WeekCount = paste0(scales::percent(WeekPercentage, accuracy = 0.1))) %>%
utils::head(top)
## Coverage
coverage <-
myTable_legends %>%
summarize(total = sum(WeekPercentage)) %>%
pull(1) %>%
scales::percent(accuracy = 0.1)
## Run plot
wp_prop_tb %>%
dplyr::mutate(patternRank = 1:nrow(.)) %>%
plot_hourly_pat(
start_hour = start_hour,
end_hour = end_hour,
legend = myTable_legends,
legend_label = "WeekCount",
legend_text = paste("Observed", subtitle_signal, "activity"),
rows = top,
title = "Patterns of digital activity",
subtitle = paste(
"Hourly activity based on",
subtitle_signal,
"sent over a week"),
caption = paste(
"Top",
top,
"patterns represent",
coverage,
"of workweeks.\n",
extract_date_range(data, return = "text")
),
ylab = paste("Top", top, "activity patterns")
)
} else if(return == "table"){
dplyr::as_tibble(myTable_return)
} else if(return == "test"){
signals_df_o
} else {
stop("Invalid `return`")
}
}
|
/scratch/gouwar.j/cran-all/cranData/wpa/R/workpatterns_rank.R
|
#' @title Generate a report on working patterns in HTML
#'
#' @description
#' `r lifecycle::badge('experimental')`
#'
#' This function takes a Hourly Collaboration query and generates a HTML report
#' on working patterns archetypes. Archetypes are created using the binary-week
#' method.
#'
#' @param data A Hourly Collaboration Query dataset in the form of a data frame.
#' @param hrvar String specifying HR attribute to cut by archetypes. Defaults to
#' `Organization`.
#' @param signals See `workpatterns_classify()`.
#' @param start_hour See `workpatterns_classify()`.
#' @param end_hour See `workpatterns_classify()`.
#' @param exp_hours See `workpatterns_classify()`.
#'
#' @param path Pass the file path and the desired file name, _excluding the file
#' extension_. For example, `"scope report"`.
#' @param timestamp Logical vector specifying whether to include a timestamp in
#' the file name. Defaults to TRUE.
#'
#' @inherit generate_report return
#'
#' @family Reports
#' @family Working Patterns
#'
#' @importFrom purrr map_if
#' @importFrom methods is
#'
#' @export
workpatterns_report <- function(data,
hrvar = "Organization",
signals = c("email", "IM"),
start_hour = "0900",
end_hour = "1700",
exp_hours = NULL,
path = "workpatterns report",
timestamp = TRUE){
## Pre-empt Date format issues
data$Date <- as.Date(data$Date, format = "%m/%d/%Y")
## Create timestamped path (if applicable)
if(timestamp == TRUE){
newpath <- paste(path, wpa::tstamp())
} else {
newpath <- path
}
## Get list output from `workpatterns_classify_bw()`
wp_list <-
data %>%
workpatterns_classify_bw(hrvar = hrvar,
signals = signals,
start_hour = start_hour,
end_hour = end_hour,
exp_hours = exp_hours,
return = "list")
## plot for `workpatterns_rank`
pd_id <-
wp_list$data %>%
mutate(PersonWeekId = paste0(PersonId,"_",Date)) %>%
select(PersonWeekId, Personas)
## plot table for `workpatterns_rank`
plot_table_list <-
data %>%
mutate(PersonWeekId = paste0(PersonId,"_",Date)) %>%
left_join(pd_id, by = "PersonWeekId") %>%
split(.$Personas)
plot_rank_list <-
plot_table_list %>%
purrr::map(function(x){
if(nrow(x) == 0){
"Low base size for this archetype."
} else {
workpatterns_rank(
x,
start_hour = start_hour,
end_hour = end_hour,
signals = signals,
return = "plot"
)
}
})
## Create custom bar plot for archetypes
# personas_table <-
# wp_list$data %>%
# dplyr::as_tibble() %>%
# dplyr::group_by(Personas) %>%
# dplyr::summarise(Count = dplyr::n()) %>%
# dplyr::mutate(Percentage = Count / sum(Count, na.rm = TRUE)) %>%
# dplyr::mutate(Percentage= scales::percent(Percentage, accuracy = 0.1))
personas_plot <-
wp_list$plot
# personas_table %>%
# ggplot(aes(x = Personas, y = Count)) +
# geom_col(fill = wpa::rgb2hex(0, 120, 212)) +
# geom_text(aes(label = Percentage),
# vjust = -1,
# fontface = "bold",
# size = 4) +
# wpa::theme_wpa_basic() +
# theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
# labs(title = "Frequency of Working Patterns",
# subtitle = "Distribution of Cases by Archetype",
# y = "Number of Cases",
# x = "",
# caption = wpa::extract_date_range(data, return = "text")) +
# scale_y_continuous(limits = c(0, max(personas_table$Count) * 1.1))
## Set outputs
output_list <-
list(
data %>% wpa::check_query(return = "text"),
data %>%
workpatterns_rank(
start_hour = start_hour,
end_hour = end_hour,
signals = signals,
return = "plot"),
personas_plot,
wp_list$table,
wp_list$plot_area,
plot_rank_list[[1]],
plot_rank_list[[2]],
plot_rank_list[[3]],
plot_rank_list[[4]],
plot_rank_list[[5]],
plot_rank_list[[6]],
plot_rank_list[[7]],
plot_rank_list[[8]]
) %>% # Expand objects to this list
purrr::map_if(is.data.frame, wpa::create_dt, rounding = 1, percent = TRUE) %>%
purrr::map_if(is.character, md2html)
## Set header titles
## The length must match `output_list`
title_list <-
c("Data Overview",
"Common Patterns",
"Archetypes",
"Split by HR Attribute",
"Time Dynamics",
paste(names(plot_table_list)[[1]]),
paste(names(plot_table_list)[[2]]),
paste(names(plot_table_list)[[3]]),
paste(names(plot_table_list)[[4]]),
paste(names(plot_table_list)[[5]]),
paste(names(plot_table_list)[[6]]),
paste(names(plot_table_list)[[7]]),
paste(names(plot_table_list)[[8]])
)
## Set header levels
## Makes use of level/header system for Markdown syntax
n_title <- length(title_list)
levels_list <- rep(3, n_title) # All chunks to have level 3 header
levels_list[c(1,2,3)] <- 2 # Set level 2 for section header
## Generate report
generate_report(title = "Working Patterns Report",
filename = newpath,
outputs = output_list,
titles = title_list,
subheaders = rep("", n_title),
echos = rep(FALSE, n_title),
levels = levels_list,
theme = "cosmo",
preamble = read_preamble("workpatterns_report.md"))
}
|
/scratch/gouwar.j/cran-all/cranData/wpa/R/workpatterns_report.R
|
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
#' @title Add a character at the start and end of a character string
#'
#' @description This function adds a character at the start and end of a character
#' string, where the default behaviour is to add a double quote.
#'
#' @param string Character string to be wrapped around
#' @param wrapper Character to wrap around `string`
#'
#' @family Support
#'
#' @return
#' Character vector containing the modified string.
#'
#' @export
wrap <- function(string, wrapper = '"'){
paste0(wrapper, string, wrapper)
}
|
/scratch/gouwar.j/cran-all/cranData/wpa/R/wrap.R
|
---
params:
data: data
stopwords: stopwords
set_title: report_title
keep: keep
seed: seed
title: "`r params$set_title`"
---
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(wpa)
## Get user data
data <- params$data
stopwords <- params$stopwords
keep <- params$keep
seed <- params$seed
```
Introduction
===============================================
Column {data-width=40%}
-------------------------------------
### Introduction
In this report, you will find analysis on **meeting subject lines**. This will allow you to refine meeting exclusion rules and identify topics that drive collaboration patterns.
Column {data-width=60%}
-------------------------------------
### Word cloud
```{r echo=FALSE, message=FALSE, warning=FALSE}
data %>% tm_wordcloud(stopwords = stopwords, keep = keep)
```
Word Frequency
===============================================
Column {data-width=50%}
-------------------------------------
### Word Frequency - Plot
```{r echo=FALSE, message=FALSE, warning=FALSE}
data %>% tm_freq(token = "words", stopwords = stopwords, keep = keep)
```
Column {data-width=50%}
-------------------------------------
### Word Frequency - Table
```{r echo=FALSE, message=FALSE, warning=FALSE}
data %>%
tm_freq(
token = "words",
stopwords = stopwords,
keep = keep,
return = "table"
) %>%
create_dt()
```
Phrase Frequency
===============================================
Column {data-width=50%}
-------------------------------------
### Phrase Frequency - Plot
```{r echo=FALSE, message=FALSE, warning=FALSE}
data %>% tm_freq(token = "ngrams", stopwords = stopwords, keep = keep)
```
Column {data-width=50%}
-------------------------------------
### Phrase Frequency - Table
```{r echo=FALSE, message=FALSE, warning=FALSE}
data %>%
tm_freq(
token = "ngrams",
stopwords = stopwords,
keep = keep,
return = "table"
) %>%
create_dt()
```
Word co-occurrence
===============================================
Column {data-width=50%}
-------------------------------------
### Word co-occurrence - Plot
```{r echo=FALSE, message=FALSE, warning=FALSE}
data %>% tm_cooc(stopwords = stopwords, seed = seed, return = "plot")
```
Column {data-width=50%}
-------------------------------------
### Word co-occurrence - Table
```{r echo=FALSE, message=FALSE, warning=FALSE}
data %>%
tm_cooc(stopwords = stopwords, seed = seed, return = "table") %>%
create_dt()
```
Top terms
===============================================
Column {data-width=50%}
-------------------------------------
### Top terms - Days
```{r echo=FALSE, message=FALSE, warning=FALSE}
data %>% subject_scan(mode = "days", stopwords = stopwords)
```
Column {data-width=50%}
-------------------------------------
### Top terms - Hours
```{r echo=FALSE, message=FALSE, warning=FALSE}
data %>% subject_scan(mode = "hours", stopwords = stopwords)
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/meeting_tm/meeting_tm_report.Rmd
|
---
params:
data: data
set_title: report_title
hrvar: hrvar
mingroup: mingroup
title: "`r params$set_title`"
---
# Minimal Report
This is a minimal report that shows basic diagnostic information about the dataset. This report is designed for testing purposes only.
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(wpa)
## Get user data
data <- params$data
hrvar <- params$hrvar
mingroup <- params$mingroup
keymetrics_scan(data,
hrvar = hrvar,
mingroup = mingroup)
```
## Email Hours
Here is a view of email hours.
```{r echo=FALSE}
create_bar(data,
hrvar = hrvar,
metric = "Email_hours",
mingroup = mingroup)
```
## Diagnostics
```{r echo=FALSE}
check_query(data)
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/minimal.Rmd
|
md2html <- function(text){
html_chunk <- markdown::markdownToHTML(text = text,
fragment.only = TRUE)
htmltools::HTML(html_chunk)
}
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/auxiliary.R
|
Collaboration
=====================================
<body style="background-color:white;font-family:arial">
<p style="color:gray;background-color:white;margin-left: 20px">
<br>
<B> <font size="+3">Is collaboration load reducing personal time?</font></B>
<br>
<br>
</p>
Column {data-width=30%}
-----------------------------------------------------------------------
### Average length of working day based on collaboration
```{r}
if(sum(my_sq_data$Work_time, na.rm = TRUE) == 0){
KPI_1 <- "0 "
} else {
KPI_1 <-
my_sq_data %>%
create_bar(metric = "Work_time",
hrvar = NULL,
return = "table") %>%
select(Work_time) %>%
pull(1) %>%
round(1)
}
paste(KPI_1, "hr work days") %>%
flexdashboard::valueBox(icon = "fa-calendar", color = "#34b1e2")
```
### <B>Are employees able to balance work and personal time?</B> <br> Employees should strive for an equal balance between work and personal time, assuming 8 hours a day is reserved for sleep. Research shows that employees who protect their personal time are more motivated and struggle less with mental health.
```{r}
if(sum(my_sq_data$Work_time, na.rm = TRUE) == 0){
md2html("## Note: there is insufficient urgent collaboration data to display.")
} else {
balance1_w1_plot1 <-
my_sq_data %>%
mutate(Personal_time = 16 - Work_time) %>%
create_stacked(metric = c("Work_time", "Personal_time"),
hrvar = hrvar,
rank = NULL) +
labs(title = "Employee workday",
subtitle = "Average hours per person per day")
balance1_w1_plot1
}
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Average collaboration time per day (meetings and emails)
```{r}
KPI_2 <- my_sq_data %>%
create_bar(metric = "dailyCollabHours",
hrvar = NULL,
return = "table") %>%
select(dailyCollabHours) %>%
pull(1) %>%
round(1)
paste(KPI_2, "hrs in collaboration") %>%
flexdashboard::valueBox(icon = "fa-user-friends", color = "#00508F")
```
### <B> Is collaboration load impacting personal time?</B> <br> High levels of daily collaboration can become disruptive to an employee’s workday, forcing them to use personal time to complete tasks and meet deadlines.
```{r}
balance1_w2_plot1 <-
my_sq_data %>%
rename(`Collaboration Hours` = "dailyCollabHours") %>%
create_bar(metric = "Collaboration Hours",
hrvar = hrvar,
bar_colour = "#00508F",
rank = NULL)
balance1_w2_plot1 +
labs(title = "Collaboration hours",
subtitle= "Average hours per person per day")
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Percentage of employees that collaborate 6 hrs + per day
```{r}
KPI_3 <-
my_sq_data %>%
create_dist(metric="dailyCollabHours",
hrvar=NULL,
cut = c(3, 6),
return="table")
if(!("6+ hours" %in% names(KPI_3))){
KPI_3 <- 0
} else {
KPI_3 <-
KPI_3 %>%
select("6+ hours") %>%
pull(1) %>%
round(2)
}
paste(KPI_3 * 100, "% over-collaborators") %>%
flexdashboard::valueBox(icon = "fa-thermometer-full",
color = "#f59b76")
```
### <B>Which employees are most impacted by collaboration load?</B> <br> Identify critical groups in the company that may be stretched with collaboration overload. Encourage these teams to streamline collaboration and preserve personal time.
```{r}
balance1_w3_plot1 <-
my_sq_data %>%
create_dist(metric="dailyCollabHours",
hrvar=hrvar,
cut = c(3, 6),
unit = "hours",
dist_colours = c("#f59b76", "#fcf0eb", "#bfe5ee"))
balance1_w3_plot1 <- balance1_w3_plot1 +
labs(title = "Collaboration distribution",
subtitle ="% of employees by daily collaboration")
balance1_w3_plot1
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_1.Rmd
|
Balance
=====================================
<body style="background-color:white;font-family:arial">
<p style="color:gray;background-color:white;margin-left: 20px">
<br>
<B><font size="+3">Can employees balance collaboration and personal time?</font></B>
<br>
<br>
</p>
Column {data-width=30%}
-----------------------------------------------------------------------
### Average daily collaboration taking place after-hours
```{r}
KPI_1 <- my_sq_data %>%
create_bar(metric="dailyAfterHours", hrvar= NULL, return="table") %>%
select(dailyAfterHours) %>%
pull(1) %>%
round(1)
paste(KPI_1, "hrs after work-hours") %>%
flexdashboard::valueBox(icon = "fa-moon",
color = rgb2hex(49, 97, 124))
```
### <B>Is after-hours work common practice?</B> <br> Although sometimes it may be necessary, habitually extending work into evenings is particularly detrimental to workers’ mental health.
```{r}
balance2_w1_plot1 <- my_sq_data %>%
rename(`After Hours Collaboration` = "dailyAfterHours") %>%
create_bar(metric = "After Hours Collaboration",
hrvar = hrvar,
return = "plot",
rank = NULL,
bar_colour = rgb2hex(49, 97, 124)) # Need to add mode of communication
balance2_w1_plot1 + labs(title = "After hours", subtitle = "Average hours per person per day")
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Percentage of employees engaging in 2+ after-hours per day
```{r}
KPI_2 <-
my_sq_data %>%
create_dist(metric = "dailyAfterHours",
hrvar = NULL,
return = "table",
cut = c(1,2))
if(!("2+ hours" %in% names(KPI_2))){
KPI_2 <- 0
} else {
KPI_2 <-
KPI_2 %>%
pull("2+ hours") %>%
.[[1]] %>%
round(3) * 100
}
paste(KPI_2, "% long after-hours") %>%
flexdashboard::valueBox(icon = "fa-calendar-plus",
color = "#f59b76")
```
### <B>Which employees are engaging in the most after hours work? </B> <br> Identify groups most at risk of losing personal time and take steps to intervene and help reduce regular after-hours.
```{r}
balance2_w2_plot1 <-
my_sq_data %>%
rename(`After Hours Collaboration` = "dailyAfterHours") %>%
create_dist(metric = "After Hours Collaboration",
hrvar = hrvar,
return = "plot",
cut = c(1,2),
dist_colours = c("#f59b76", "#fcf0eb", "#bfe5ee"))
balance2_w2_plot1 +
labs(title = "After hours distribution",
subtitle = "% of employees by daily after hours collaboration")
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Percentage of employees active on weekends at least once per month
```{r}
if(sum(my_sq_data$monthly_weekend_work, na.rm = TRUE) == 0){
KPI_3 <- 0
} else {
KPI_3 <-
my_sq_data %>%
create_bar(metric = "monthly_weekend_work", hrvar = NULL, return="table") %>%
pull("monthly_weekend_work") %>%
.[[1]] %>%
round(3)* 100
}
# Need to calculate right KPI
paste(KPI_3, "% weekend workers") %>%
flexdashboard::valueBox(icon = "fa-calendar-times",
color = "#5B0F66")
```
### <B>Are employees engaging in regular weekend work?</B> <br> Switching on for even a short period of time on weekends can siginifcantly harm employee wellbeing.
```{r}
if(sum(my_sq_data$Frequency_of_weekend_work, na.rm = TRUE) == 0){
md2html("## Note: there is insufficient data to display.")
} else {
my_sq_data %>%
mutate(
across(.cols = Frequency_of_weekend_work,
.fns = ~ifelse(!is.finite(.), 52, .))) %>% # Assume once a year = Never
group_by(!!sym(hrvar), PersonId) %>%
summarise(
across(
.cols = Frequency_of_weekend_work,
.fns = ~median(., na.rm = TRUE)
),
.groups = "drop"
) %>%
group_by(!!sym(hrvar)) %>%
summarise(
Frequency_of_weekend_work = median(Frequency_of_weekend_work, na.rm = TRUE),
n = n_distinct(PersonId)
) %>%
filter(n >= 5) %>%
ggplot(aes(x = Frequency_of_weekend_work,
y = !!sym(hrvar),
colour = "Frequency of weekend work")) +
geom_point(size = 3) +
scale_colour_manual(
name="",
values = "#5B0F66",
# guide = "Frequency of weekend work"
) +
scale_x_reverse(
limits = c(15, 1),
breaks = c(1, 52/12, 52/6, 13),
labels = c("Weekly", "Monthly", "Bi-Monthly", "Quarterly"),
position = "top"
) +
labs(title = "Weekend work",
subtitle = "Median frequency of weekend work",
caption = extract_date_range(my_sq_data, return = "text")) +
theme_wpa_basic() +
theme(axis.line.y = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.grid.major.y = element_line(color="gray"),
panel.grid.major.x = element_line(colour = "#D9E7F7", size = 5))
}
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_2.Rmd
|
Urgency
=====================================
<body style="background-color:white;font-family:arial">
<p style="color:gray;background-color:white;margin-left: 20px">
<br>
<B>
<font size="+3">
Can teams respond to urgent needs without risking employee wellbeing?
</font>
</B>
<br>
<br>
</p>
<!--
<p>
<a class="btn btn-primary btn-lg btn-block" data-toggle="collapse" href="#collapseExample6" role="button" aria-expanded="false" aria-controls="collapseExample6">
Resilience: Is the organisation able to respond to urgent needs without risking employee wellbeing?
</a>
</p>
<div class="collapse" id="collapseExample6">
<div class="card card-body">
Companies need to cope with unexpected demands without impacting work-life balance. Protect groups with high levels of urgency and after-hours work by shifting towards more planned activities.
</div>
</div>
<hr>
-->
Column {data-width=30%}
-----------------------------------------------------------------------
### % of work weeks included urgent collaboration
```{r}
## Pre-calculation
## Summary table for urgency
urg_sum_tb <-
list(
my_sq_data %>%
group_by(!!sym(hrvar), PersonId) %>%
summarise(across(IsUrgent, ~any(., na.rm = TRUE)), .groups = "drop") %>% # TRUE if any
group_by(!!sym(hrvar)) %>%
summarise(across(IsUrgent, ~mean(., na.rm = TRUE))) %>%
rename(PercentageAffected = "IsUrgent"),
my_sq_data %>%
group_by(!!sym(hrvar), PersonId) %>%
summarise(across(IsUrgent, ~sum(., na.rm = TRUE)), .groups = "drop") %>%
group_by(!!sym(hrvar)) %>%
summarise(across(IsUrgent, ~mean(., na.rm = TRUE))) %>%
rename(NumberUrgentWeeks = "IsUrgent"),
my_sq_data %>%
hrvar_count(hrvar,
return = "table")
) %>%
purrr::reduce(full_join, by = hrvar) %>%
filter(n >= 5)
if(sum(my_sq_data$IsUrgent, na.rm = TRUE) == 0){
urg_percent <- "0 %"
} else {
urg_percent <- scales::percent(mean(my_sq_data$IsUrgent))
}
## KPI box
paste(urg_percent, "urgent collaboration") %>%
flexdashboard::valueBox(icon = "fa-exclamation")
```
### <B>Which teams are affected by urgent needs more?</B> <br> Work can be unpreditcable and there will be urgent requests, but an overwhelming amount will prevent employees from being able to complete business-as-usual activities.
```{r}
if(sum(my_sq_data$IsUrgent, na.rm = TRUE) == 0){
md2html("## Note: there is insufficient urgent collaboration data to display.")
} else {
urg_sum_tb %>%
ggplot(aes(x = PercentageAffected,
y = NumberUrgentWeeks,
colour = !!sym(hrvar),
size = n)) +
geom_point(alpha = 0.8) +
theme_wpa_basic() +
labs(
title = "Urgent Collaboration",
subtitle = "Impact and Frequency of Emails with 'Urgent' keywords",
x = "% of employees affected",
y = "Urgent weeks per employee (average)",
caption = paste("Bubble size measures number of people in organization.",
extract_date_range(my_sq_data, return = "text"))) +
scale_size(range = c(1, 20)) +
scale_x_continuous(labels = scales::percent) +
ggrepel::geom_text_repel(aes(label = !!sym(hrvar)),
size = 3,
force_pull = -0.02,
colour = "grey40") +
theme(
legend.position = "none"
)
}
```
Column {data-width=30%}
-----------------------------------------------------------------------
### % change in after-hours when urgent collaboration is present
```{r}
urg_calc <- my_sq_data %>%
group_by(IsUrgent) %>%
summarise(across(After_hours_collaboration_hours, ~mean(.)))
any_urg <-
urg_calc %>%
filter(IsUrgent == TRUE) %>%
nrow()
afch_urg <-
urg_calc %>%
filter(IsUrgent == TRUE) %>%
pull(After_hours_collaboration_hours)
afch_nonurg <-
urg_calc %>%
filter(IsUrgent == FALSE) %>%
pull(After_hours_collaboration_hours)
afch_display <- (afch_urg - afch_nonurg) / afch_nonurg
if(any_urg == 0){
afch_display <- "0 %"
} else {
afch_display <- scales::percent(afch_display)
}
afch_display %>%
paste("change in after hours") %>%
flexdashboard::valueBox(icon = "fa-moon",
color = "#f59b76")
```
### <B>Is the organization able to respond to urgent needs without risking employee wellbeing?</B> <br> Companies need to cope with unexpected demands without impacting work-life balance. Protect groups with high levels of urgency and after-hours work by shifting towards more planned activities.
```{r}
groups_above_mingroup <-
my_sq_data %>%
hrvar_count(hrvar = hrvar, return = "table") %>%
filter(n >= 5) %>%
pull(!!sym(hrvar))
if(sum(my_sq_data$IsUrgent, na.rm = TRUE) == 0){
md2html("## Note: there is insufficient urgent collaboration data to display.")
} else {
my_sq_data %>%
filter(!!sym(hrvar) %in% groups_above_mingroup) %>%
group_by(IsUrgent, !!sym(hrvar)) %>%
summarise(across(After_hours_collaboration_hours, ~mean(.)), .groups = "drop") %>%
mutate(Urgent_collaboration =
case_when(IsUrgent == TRUE ~ "Urgent weeks",
IsUrgent == FALSE ~ "Non-urgent weeks")) %>%
ggplot(aes(x = After_hours_collaboration_hours,
y = !!sym(hrvar),
colour = Urgent_collaboration)) +
geom_point(size = 3) +
scale_x_continuous(position = "top") +
scale_colour_manual(
name = "Urgent collaboration",
values = c(
"Non-urgent weeks" = "#00508F",
"Urgent weeks" = "#f59b76"
)
) +
theme_wpa_basic() +
labs(title = "After hours collaboration",
subtitle = "Average hours per person per week",
caption = extract_date_range(my_sq_data, return = "text"),
x = us_to_space("After_hours_collaboration_hours")) +
theme(
axis.line=element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(colour = "#D9E7F7", size = 3), # lightblue bar
panel.grid.minor.x = element_line(color="gray"),
strip.placement = "outside",
strip.background = element_blank(),
strip.text = element_blank(),
axis.title = element_blank()
) +
geom_vline(xintercept =
my_sq_data %>%
afterhours_sum(hrvar = NULL,
return = "table") %>%
pull(After_hours_collaboration_hours),
colour = "red")
}
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_3.Rmd
|
Flexibility
=====================================
<body style="background-color:white;font-family:arial">
<p style="color:gray;background-color:white;margin-left: 20px">
<br>
<B>
<font size="+3">
Are employees embracing flexible work schedules?
</font>
</B>
<br>
<br>
</p>
Column {data-width=30%}
-----------------------------------------------------------------------
### Percentage of weeks employees define their own start times
```{r}
KPI_1 <-
flex_index_data %>%
create_bar(
metric = "ChangeHours",
hrvar = NULL,
return="table") %>%
select(ChangeHours) %>%
pull(1) %>%
round(3)*100
paste(KPI_1, "% define start time") %>%
flexdashboard::valueBox(icon = "fa-hourglass-start",
color = "#34b1e2")
```
### <B>Are employees freely defining their start time?</B> <br> Teams that embrace flexibility allow members of the team to start their workday at different times. Employees should be able to follow a schedule that suits their needs, than those imposed by an employer.
```{r}
# Convert `start_hour` into an hour slot string
hr_slot <- function(x){
h_str <- as.numeric(substr(x, start = 1, stop = 2))
m_str <- substr(x, start = 3, stop = 4) # keep as string
apm <- ifelse(h_str < 12, "AM", "PM")
slot1 <- paste0(h_str)
slot2 <- paste0(h_str + 1)
paste0(slot1, "-", slot2, apm)
}
flex2_w1_plot <-
flex_index_data %>%
mutate(Percentage_of_weeks = ChangeHours) %>%
create_bar(metric = "Percentage_of_weeks",
hrvar = hrvar,
rank = NULL,
xlim = 1,
bar_colour = "#34b1e2",
percent = TRUE)
flex2_w1_plot +
labs(title = "Define start times",
subtitle = paste("% of weeks employees start outside", hr_slot(start_hour), "window"))
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Percentage of weeks employees have recurring disconnection time
```{r}
KPI_3 <- flex_index_data %>%
create_bar(
metric = "TakeBreaks",
hrvar = NULL,
return="table") %>%
select(TakeBreaks) %>%
pull(1) %>%
round(3)*100
paste(KPI_3, "% define quiet hours") %>%
flexdashboard::valueBox(icon = "fa-stopwatch",
color = rgb2hex(1, 147, 157))
```
### <B>Are employees disconnecting at a recurring time during the week?</B> <br> Employees should have the freedom to define their weekday by taking recurring disconnection time to suit their needs. In teams that embrace flexibility, members will choose to organize / split their day in different ways (e.g. take a long lunch-break, disconnect in the afternoon and reconnect in the evening, etc.)
```{r}
flex2_w3_plot <-
flex_index_data %>%
mutate(Percentage_of_weeks = TakeBreaks) %>%
create_bar(
metric = "Percentage_of_weeks",
hrvar = hrvar,
xlim = 1,
rank = NULL,
bar_colour = rgb2hex(1, 147, 157),
percent = TRUE
)
flex2_w3_plot +
labs(title = "Recurring disconnection time",
subtitle = paste("% of weeks employees have recurring disconnection"))
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Percentage of weeks employees limit their activity to 8 or less distinct hours
```{r}
KPI_2 <- flex_index_data %>%
create_bar(
metric = "ControlHours",
hrvar = NULL,
return="table") %>%
select(ControlHours) %>%
pull(1) %>%
round(3)*100
paste(KPI_2, "% control active hours") %>%
flexdashboard::valueBox(icon = "fa-balance-scale",
color = "#00508F")
```
### <B>Are employees able to control their active hours?</B> <br> Employees who choose alternative work schedules should be able to maintain a workload that is broadly equivalent to the standard 8 hours. Flexible working should not result in longer hours spread across the day.
```{r}
flex2_w2_plot <- flex_index_data %>%
mutate(Percentage_of_weeks = ControlHours) %>%
create_bar(
metric = "Percentage_of_weeks",
hrvar = hrvar,
xlim = 1,
rank = NULL,
bar_colour = "#00508F",
percent = TRUE,
text_just = 2.5,
text_colour = "#00508F"
)
flex2_w2_plot +
labs(title = "Control active hours",
subtitle = paste("% of weeks employees control active hours"))
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_4.Rmd
|
Activity patterns
=====================================
<body style="background-color:white;font-family:arial">
<p style="color:gray;background-color:white;margin-left: 20px">
<br>
<B>
<font size="+3">
Are employees able to switch off?
</font>
</B>
<br>
<br>
</p>
Column {data-width=30%}
-----------------------------------------------------------------------
### Distinct hours with email / chat in the most frequent activity pattern
```{r}
KPI_1 <-
my_em_data %>% workpatterns_rank(return="table") %>% arrange( desc(WeekCount)) %>% filter(row_number()==1) %>%
mutate(Signals_Total = select(., starts_with("Signals_sent_")) %>%
apply(1, sum, na.rm = TRUE)) %>% select(Signals_Total) %>% pull(1)
paste(KPI_1 ,"hours with activity") %>%
flexdashboard::valueBox(icon = "fa-arrows-alt", color = "#f59b76")
```
### <B> When are employees engaging with work? </B> <br> Individuals may work outside regular working hours to deal with excessive workload, or to take advantage of flexible working arragements. Digital activity patterns reveals if groups are able to disconnect regularly.
```{r}
flexibility1_w3_plot1 <- my_em_data %>% workpatterns_rank()
flexibility1_w3_plot1
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Percentage of "always on" weeks based on collaboration patterns
```{r}
KPI_1 <-
wp_list$data %>%
count(Personas) %>%
mutate(prop = n / sum(n)) %>%
select(Personas, Total = "prop") %>%
filter(Personas == "6 Always on (13h+)") %>%
select(Total) %>%
pull(1) %>%
round(3)*100
paste(KPI_1, "% always-on") %>%
flexdashboard::valueBox(icon = "fa-lightbulb", color = "#325369" )
```
### <B>Are employees able to switch off? </B> <br> Individuals that work long, continuous hours without breaks or remain actively engaged with work after hours can experience a deterioration of their wellbeing.
```{r}
flexibility1_w1_plot1 <- wp_list$plot
flexibility1_w1_plot1 +
labs(title = "Classification of activity patterns", subtitle = "Frequency of common archetypes")
```
Column {data-width=30%}
-----------------------------------------------------------------------
### is the group where employees have the highest % of "always on" weeks
```{r}
KPI_2 <-
wp_list$table %>%
filter(Personas =="6 Always on (13h+)") %>%
pivot_longer(cols = -Personas, names_to = "group", values_to = "alwaysOn") %>%
filter(group %in% mingroup_str) %>%
arrange(desc(alwaysOn)) %>%
pull(group) %>%
.[[1]]
KPI_2 %>% flexdashboard::valueBox(icon = "fa-search")
```
### <B>Which teams are most affected? </B> <br> Identify groups with highest prevalence the negative activity patterns and encourage them to disconnect and build regular breaks in their work day.
```{r}
round_percent <- function(x){
scales::percent(x, accuracy = 1)
}
wp_list$data %>%
mutate(Personas = case_when(Personas == "0 < 3 hours on" ~ "Low\nactivity",
Personas == "1 Standard with breaks workday" ~ "Flexible",
Personas == "2 Standard continuous workday" ~ "Standard",
Personas == "3 Standard flexible workday" ~ "Flexible",
Personas == "4 Long flexible workday" ~ "Long\nflexible",
Personas == "5 Long continuous workday" ~ "Long\ncontinuous",
Personas == "6 Always on (13h+)" ~ "Always\non"
) %>%
factor(levels =
c("Low\nactivity",
"Standard",
"Flexible",
"Long\nflexible",
"Long\ncontinuous",
"Always\non"))) %>%
count(!!sym(hrvar), Personas) %>%
filter(!!sym(hrvar) %in% mingroup_str) %>%
group_by(!!sym(hrvar)) %>%
mutate(percent = n / sum(n)) %>%
ungroup() %>%
ggplot(aes(x = Personas,
y = !!sym(hrvar),
fill = percent)) +
geom_tile() +
geom_text(aes(label = scales::percent(percent, accuracy = 1)),
size = 3) +
scale_fill_gradientn(name = "Row percentages",
colours = c("steelblue4",
"aliceblue",
"white",
"mistyrose1",
"tomato1"),
labels = round_percent) +
# viridis::scale_fill_viridis(labels = scales::percent) +
scale_x_discrete(position = "top") +
theme_wpa_basic() +
theme(axis.text.x = element_text(angle = 50,
vjust = 0.5,
hjust = 0),
axis.title = element_blank(),
plot.margin=unit(c(0, 0, 0, 0),"cm"),
legend.text=element_text(size = 8)) +
labs(title = "Activity pattern distribution",
subtitle = "Distribution of archetypes",
caption = extract_date_range(wp_list$data, return = "text"))
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_5.Rmd
|
Focus
=====================================
<body style="background-color:white;font-family:arial">
<p style="color:gray;background-color:white;margin-left: 20px">
<br>
<B>
<font size="+3">
Are employees able to engage in uninterrupted focus time?
</font>
</B>
<br>
<br>
</p>
Column {data-width=30%}
-----------------------------------------------------------------------
### total hours available for focus work per person per day
```{r}
KPI_1 <- my_sq_data %>%
create_bar(hrvar = NULL,
metric = "Total_focus_hours_daily",
return = "table") %>%
pull("Total_focus_hours_daily") %>%
round(1)
paste(KPI_1, "total focus hours") %>%
flexdashboard::valueBox(icon = "fa-user-edit",
color = "#34b1e2")
```
### <B> Are employees able to engage in uninterrupted focus time? </B> <br> Meeting-free focus time is vital for employees to be able to complete individual tasks, think creatively, and address critical business demands. Employees are able to engage in high quality focus time if there is a break of 2 hours between meetings.
```{r}
resilience1_w1_plot1 <-
my_sq_data %>%
create_bar(hrvar = hrvar,
metric = "Total_focus_hours_daily",
rank = NULL,
percent = FALSE)
resilience1_w1_plot1 +
labs(title = "Focus Time",
subtitle = paste("Average hours per person per day"))
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Average unscheduled collaboration per person each day
```{r}
if(sum(my_sq_data$Unscheduled_collaboration_hours_daily, na.rm = TRUE) == 0){
KPI_4 <- 0
} else {
KPI_4 <-
my_sq_data %>%
create_bar(hrvar = NULL,
metric = "Unscheduled_collaboration_hours_daily",
return ="table") %>%
pull(Unscheduled_collaboration_hours_daily) %>%
.[[1]] %>%
round(1)
}
paste(KPI_4, "unscheduled collaboration hours") %>%
flexdashboard::valueBox(icon = "fa-phone",
color = "#f59b76")
```
### <B> Is time for individual work prioritized and respected? </B> <br> High levels of unscheduled collaboration (emails, chats, calls) could risk the quality of focus time by breaking employees’ concentration and cause disruption.
```{r}
if(sum(my_sq_data$Unscheduled_collaboration_hours_daily, na.rm = TRUE) == 0){
md2html("## Note: there is insufficient data to display.")
} else {
resilience1_w2_plot1 <- my_sq_data %>%
create_bar(hrvar = hrvar,
rank = NULL,
bar_colour = "#f59b76",
metric = "Unscheduled_collaboration_hours_daily")
resilience1_w2_plot1 +
labs(title = "Unscheduled Collaboration",
subtitle = paste("Average hours per person per day"))
}
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_6.Rmd
|
Community
=====================================
<body style="background-color:white;font-family:arial">
<p style="color:gray;background-color:white;margin-left: 20px">
<br>
<B>
<font size="+3">
Are employees maintaining communities within the workplace?
</font>
</B>
<br>
<br>
</p>
Column {data-width=30%}
-----------------------------------------------------------------------
### Average hours in 1:1 meetings per person each week
```{r}
if(sum(my_sq_data$Intimate_1_on_1_meeting_hours, na.rm = TRUE) == 0){
p_text <- "0"
} else {
p_text <-
my_sq_data %>%
summarise(
across(
.cols = c(Intimate_1_on_1_meeting_hours),
.fns = ~mean(., na.rm = TRUE)
)
) %>%
pull(Intimate_1_on_1_meeting_hours) %>%
round(digits = 1)
}
p_text <- paste(p_text[[1]], "hours 1:1 meetings")
flexdashboard::valueBox(value = p_text,
icon = "fa-users",
color = rgb2hex(1, 147, 157))
```
### <B>Are employees part of communities in the workplace?</B> <br> Social and professional support at work ensures employees are safeguarded against feeling isolated. Successful rapport is built when employees meet in small group settings with two to five people attending.
```{r}
if(
sum(my_sq_data$Intimate_group_meeting_hours, na.rm = TRUE) == 0 |
sum(my_sq_data$Intimate_1_on_1_meeting_hours, na.rm = TRUE) == 0
){
md2html("## Note: there is insufficient collaboration data to display.")
} else {
my_sq_data %>%
create_stacked(
hrvar = hrvar,
rank = NULL,
metrics = c("Intimate_group_meeting_hours", "Intimate_1_on_1_meeting_hours"),
stack_colours = c("Intimate_group_meeting_hours" = rgb2hex(49, 97, 124),
"Intimate_1_on_1_meeting_hours" = rgb2hex(1, 147, 157)),
plot_title = "Intimate meetings",
plot_subtitle = "Average meeting hours per person each week"
)
}
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Average hours in intimate group meetings per person each week
```{r}
if(sum(my_sq_data$Intimate_group_meeting_hours, na.rm = TRUE) == 0){
p_text <- "0"
} else {
p_text <-
my_sq_data %>%
summarise(
across(
.cols = c(Intimate_group_meeting_hours),
.fns = ~mean(., na.rm = TRUE)
)
) %>%
pull(Intimate_group_meeting_hours) %>%
round(digits = 1)
}
p_text <- paste(p_text[[1]], "hours intimate group meetings")
flexdashboard::valueBox(value = p_text,
icon = "fa-users",
color = rgb2hex(49, 97, 124))
```
### <B>Are employees maintaining these communities?</B> <br> Over time, relationships can fade and thus it is important to continue strengthening existing relationships and building new connections.
```{r}
if(
sum(my_sq_data$Intimate_group_meeting_hours, na.rm = TRUE) == 0 |
sum(my_sq_data$Intimate_1_on_1_meeting_hours, na.rm = TRUE) == 0
){
md2html("## Note: there is insufficient collaboration data to display.")
} else {
my_sq_data %>%
mutate(Date = as.Date(Date, format = "%m/%d/%Y")) %>%
group_by(Date) %>%
summarise(
across(
.cols = c(Intimate_group_meeting_hours, Intimate_1_on_1_meeting_hours),
.fns = ~mean(., na.rm = TRUE)
)
) %>%
pivot_longer(cols = c(Intimate_group_meeting_hours,
Intimate_1_on_1_meeting_hours),
names_to = "Metrics",
values_to = "Hours") %>%
ggplot(aes(x = Date,
y = Hours,
group = Metrics,
fill = Metrics)) +
geom_area() +
scale_fill_manual(values =
c("Intimate_group_meeting_hours" = rgb2hex(49, 97, 124),
"Intimate_1_on_1_meeting_hours" = rgb2hex(1, 147, 157)),
labels = us_to_space) +
theme_wpa_basic() +
labs(
title = "Time in intimate meetings",
subtitle = "Average meeting hours per person each week",
caption = extract_date_range(my_sq_data, return = "text")
)
}
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_7.Rmd
|
Informal Communication
=====================================
<body style="background-color:white;font-family:arial">
<p style="color:gray;background-color:white;margin-left: 20px">
<br>
<B>
<font size="+3">
Are employees connecting informally?
</font>
</B>
<br>
<br>
</p>
Column {data-width=30%}
-----------------------------------------------------------------------
### Chats sent on average per person each week
```{r}
KPI_1 <-
my_sq_data %>%
create_bar(metric = "Instant_messages_sent",
hrvar = NULL,
return = "table") %>%
select(Instant_messages_sent) %>%
pull(1) %>%
round(1)
paste(KPI_1, "weekly chats") %>%
flexdashboard::valueBox(icon = "fa-users",
color = "#34b1e2")
```
### <B>Are employees connecting informally?</B> <br> Boost employee satisfaction and increase networks through informal communication using teams chats.
```{r}
community2_w1_plot1 <-
my_sq_data %>%
rename(Chats_sent = "Instant_messages_sent") %>%
create_bar(metric = "Chats_sent",
hrvar=hrvar,
rank = NULL
)
community2_w1_plot1 <-
community2_w1_plot1 +
labs(title = "Weekly chats",
subtitle= "Average chats sent per person each week")
community2_w1_plot1
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Percentage of writen communication conducted informally via chats
```{r}
# Custom formatter for IMs
format_im <- function(x){
x <- gsub(pattern = "Instant_messages_",
replacement = "Chats_",
x = x)
us_to_space(x)
}
p_table <-
my_sq_data %>%
group_by(PersonId) %>%
summarise(
across(
.cols = c(Instant_messages_sent,
Emails_sent),
.fns = ~mean(., na.rm = TRUE)
),
.groups = "drop"
) %>%
summarise(
across(
.cols = c(Instant_messages_sent,
Emails_sent),
.fns = ~mean(., na.rm = TRUE)
)
) %>%
mutate(Answer = Instant_messages_sent / (Instant_messages_sent + Emails_sent))
KPI_2 <- p_table$Answer %>%
scales::percent() %>%
.[[1]]
paste(KPI_2, "proportion of chats") %>%
flexdashboard::valueBox(icon = "fa-users",
color = rgb2hex(1, 147, 157))
```
### <B>Can email activity be conducted via IM instead?</B> <br> Teams chats can help employees gain answers to questions faster and feel more connected to their colleagues, fostering friendships.
```{r}
my_sq_data %>%
group_by(PersonId, !!sym(hrvar)) %>%
summarise(
across(
.cols = c(Instant_messages_sent,
Emails_sent),
.fns = ~mean(., na.rm = TRUE)
),
.groups = "drop"
) %>%
group_by(!!sym(hrvar)) %>%
summarise(
Instant_messages_sent = mean(Instant_messages_sent, na.rm = TRUE),
Emails_sent = mean(Emails_sent, na.rm = TRUE),
n = n_distinct(PersonId)
) %>%
filter(n >= 5) %>%
pivot_longer(cols = c(Instant_messages_sent, Emails_sent),
names_to = "Metrics",
values_to = "Sent") %>%
group_by(!!sym(hrvar)) %>%
mutate(Sent = Sent/sum(Sent, na.rm = TRUE)) %>%
mutate(Metrics = factor(Metrics,
levels = rev(c("Instant_messages_sent",
"Emails_sent")))
) %>%
ggplot(aes(x = !!sym(hrvar),
y = Sent,
fill = Metrics)) +
geom_col(position = "stack") +
geom_text(aes(colour = Metrics,
label = scales::percent(Sent, accuracy = 1)),
position = position_stack(vjust = .5)) +
scale_fill_manual(values = c(
"Instant_messages_sent" = rgb2hex(1, 147, 157),
"Emails_sent" = rgb2hex(189, 191, 192)),
labels = format_im,
guide = guide_legend(reverse = TRUE)
) +
scale_colour_manual(values = c(
"Instant_messages_sent" = "#FFFFFF",
"Emails_sent" = "#FFFFFF"), guide = FALSE) +
theme_wpa_basic() +
theme(
axis.line.y = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank()) +
scale_y_continuous(labels = scales::percent, position = "right") +
coord_flip() +
labs(title = "Written communciation",
subtitle = "Percentage of written communication by type",
caption = extract_date_range(my_sq_data, return = "text"))
```
Column {data-width=30%}
-----------------------------------------------------------------------
### Percentage of chats that occurs across levels
```{r}
if(
sum(my_sq_data$IMs_sent_other_level, na.rm = TRUE) == 0 |
sum(my_sq_data$IMs_sent_same_level, na.rm = TRUE) == 0
){
KPI_2 <- "0%"
} else {
p_table <-
my_sq_data %>%
group_by(PersonId) %>%
summarise(
across(
.cols = c(IMs_sent_other_level,
IMs_sent_same_level),
.fns = ~mean(., na.rm = TRUE)
),
.groups = "drop"
) %>%
summarise(
across(
.cols = c(IMs_sent_other_level,
IMs_sent_same_level),
.fns = ~mean(., na.rm = TRUE)
)
) %>%
mutate(Answer = IMs_sent_other_level / (IMs_sent_other_level + IMs_sent_same_level))
KPI_2 <- p_table$Answer %>%
scales::percent() %>%
.[[1]]
}
paste(KPI_2, "chats across levels") %>%
flexdashboard::valueBox(icon = "fa-users",
color = rgb2hex(0, 43, 73))
```
### <B>Are employees engaging with people other than their peers?</B> <br> Encourage employees to engage with members of the team that not just their peers to help them feel a stronger sense of community.
```{r}
if(
sum(my_sq_data$IMs_sent_other_level, na.rm = TRUE) == 0 |
sum(my_sq_data$IMs_sent_same_level, na.rm = TRUE) == 0
){
md2html("## Note: there is insufficient collaboration data to display.")
} else {
my_sq_data %>%
mutate(Informal_same_level = IMs_sent_same_level,
Informal_other_level = IMs_sent_other_level) %>%
group_by(PersonId, !!sym(hrvar)) %>%
summarise(
across(
.cols = c(Informal_same_level, Informal_other_level),
.fns = ~mean(., na.rm = TRUE)
),
.groups = "drop"
) %>%
group_by(!!sym(hrvar)) %>%
summarise(
Same_level = mean(Informal_same_level, na.rm = TRUE),
Across_levels = mean(Informal_other_level, na.rm = TRUE),
n = n_distinct(PersonId)
) %>%
filter(n >= 5) %>%
pivot_longer(cols = c(Same_level, Across_levels),
names_to = "Metrics",
values_to = "Sent") %>%
group_by(!!sym(hrvar)) %>%
mutate(Sent = Sent/sum(Sent, na.rm = TRUE)) %>%
mutate(Metrics = factor(Metrics,
levels = rev(c("Across_levels","Same_level")))
) %>%
ggplot(aes(x = !!sym(hrvar),
y = Sent,
fill = Metrics)) +
geom_col(position = "stack") +
geom_text(aes(colour = Metrics,
label = scales::percent(Sent, accuracy = 1)),
position = position_stack(vjust = .5)) +
scale_fill_manual(values = c(
"Same_level" = rgb2hex(189, 191, 192) ,
"Across_levels" = rgb2hex(0, 43, 73)
),
labels = us_to_space,
guide = guide_legend(reverse = TRUE)
) +
scale_colour_manual(values = c(
"Same_level" = "#FFFFFF",
"Across_levels" = "#FFFFFF"
), guide = FALSE) +
theme_wpa_basic() +
theme(
axis.line.y = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank()) +
scale_y_continuous(labels = scales::percent, position = "right") +
coord_flip() +
labs(title = "Chats distribution",
subtitle = "Percentage of chats sent",
caption = extract_date_range(my_sq_data, return = "text"))
}
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_8.Rmd
|
Introduction
=====================================
<div class="jumbotron" style="background-color:#FFFFFF;">
<!--<img src="Microsoft-Viva-Insights-logo.png" style="float:right;width:180px;height:180px;">-->
<h1 class="display-4">Employee Wellbeing Report</h1>
<p class="lead" style="color:gray;"> <B> Microsoft Viva | Organisational Insights </B></p>
<hr class="my-4">
<p> <font size="+1"> <em> Employee wellbeing has demonstrated the ability to improve employee engagement, retention and productivity within a company.
<br> Get insights into employee wellbeing across your company and uncover opportunities to improve work life balance, flexible working opportunities, organizational resilience and a sense of community. </em> </font></p>
<br>
<h4>Table of Contents</p>
<div class="row">
<div class="col-md-6"><!-- first column -->
<div class="list-group">
<a href="#collaboration" class="list-group-item">1. Collaboration</a>
<a href="#balance" class="list-group-item">2. Balance</a>
<a href="#urgency" class="list-group-item">3. Urgency</a>
<a href="#flexibility" class="list-group-item">4. Flexibility</a>
</div>
</div>
<div class="col-md-6"><!-- second column -->
<div class="list-group">
<a href="#activity-patterns" class="list-group-item">5. Activity Patterns</a>
<a href="#focus" class="list-group-item">6. Focus</a>
<a href="#community" class="list-group-item">7. Community</a>
<a href="#informal-communication" class="list-group-item">8. Informal communication</a>
</div>
</div>
</div>
<p class="lead">
<a class="btn btn-primary btn-lg" href="#collaboration" role="button">Start exploring</a>
</p>
</div>
<br>
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_cover_4.Rmd
|
Notes
=====================================
Column {data-width=20%}
-----------------------------------------------------------------------
### Report Notes
```{r}
flexdashboard::valueBox(
value = "",
color = rgb2hex(130, 130, 130)
)
```
### <B>Report Notes</B> {.no-title}
```{r}
end_time <- Sys.time()
text1 <- paste("This report was generated on ", format(Sys.time(), "%b %d %Y"), ".")
text2 <- my_sq_data %>% check_query(return = "text", validation = TRUE)
text3 <- paste("Total Runtime was: ", difftime(end_time, start_time, units = "mins") %>% round(2), "minutes.")
paste(text1, text2, text3, sep = "\n\n" )%>% md2html()
```
Column {data-width=80%}
-----------------------------------------------------------------------
### Glossary
```{r}
flexdashboard::valueBox(
value = "",
color = rgb2hex(130, 130, 130)
)
```
### <B> Glossary </B> {.no-title}
```{r}
gloss_tb %>%
create_dt(
freeze = 0
)
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_notes.Rmd
|
Trends
=====================================
<body style="background-color:white;font-family:arial">
<p style="color:gray;background-color:white;margin-left: 20px">
<br>
<B><font size="+3">How are behaviors impacting wellbeing evolving?</font></B>
<br>
<br>
</p>
<!--
<style>
.chart-title {
font-family: Arial;
height:40px;
display: inline-block;
overflow: auto;
}
</style>
-->
Column {data-width=33%}
-----------------------------------------------------------------------
### <b>Balance</b> {.no-title}
```{r}
# Weekend work
# % Active on the weekend
if(sum(my_sq_data$Weekend_work, na.rm = TRUE) == 0){
md2html("## Note: there is insufficient data to display.")
} else {
create_tracking(
data = my_sq_data,
metric = "Weekend_work",
plot_title = "Weekend work",
plot_subtitle = "% of employees active on the weekend",
percent = TRUE
)
}
```
### <b>Focus</b> {.no-title}
```{r}
# % of work week with focus time
create_tracking(
data = my_sq_data,
metric = "Total_focus_hours_daily",
plot_title = "Focus Time",
plot_subtitle = "Average daily focus hours",
percent = FALSE
)
```
Column {data-width=33%}
-----------------------------------------------------------------------
### <b>Flexibility</b> {.no-title}
```{r}
# % of employees who limit their activity to 8 or fewer distinct hours
create_tracking(
data = flex_index_data,
metric = "ControlHours",
plot_title = "Control Active Hours",
plot_subtitle = "% of employees controlling active hours",
percent = TRUE
)
```
### <b>Urgency</b> {.no-title}
```{r}
# PREVIOUS: Average after hours collaboration for urgent weeks
if(sum(my_sq_data$IsUrgent, na.rm = TRUE) == 0){
md2html("## Note: there is insufficient data to display.")
} else {
my_sq_data %>%
# filter(IsUrgent == TRUE) %>%
create_tracking(
metric = "IsUrgent",
plot_title = "Urgent collaboration",
plot_subtitle = "% of employees who have experienced urgent collaboration",
percent = TRUE
)
}
```
Column {data-width=33%}
-----------------------------------------------------------------------
### <b>Activity patterns</b> {.no-title}
```{r}
# Always on
# % of employees who are active for over 13+ hours a day
wp_list$data %>%
mutate(IsAlwaysOn = (Personas == "6 Always on (13h+)")) %>%
create_tracking(
metric = "IsAlwaysOn",
plot_title = "Always On",
plot_subtitle = "% of employees who are active for over 13+ hour blocks a day",
percent = TRUE
)
```
### <b>Community</b> {.no-title}
```{r}
# small group meetings
# % of meeting time in a small group setting
if(sum(my_sq_data$Intimate_group_meeting_hours, na.rm = TRUE) == 0){
md2html("## Note: there is insufficient data to display.")
} else {
my_sq_data %>%
mutate(SmallGroupMeetingPercent = Intimate_group_meeting_hours / Meeting_hours) %>%
create_tracking(
metric = "SmallGroupMeetingPercent",
plot_title = "Small group meetings",
plot_subtitle = "Average % of meeting time in a small group setting",
percent = TRUE
)
}
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/db_trends.Rmd
|
---
params:
wbq: wbq
hcq: hcq
set_title: report_title
hrvar: hrvar
mingroup: mingroup
start_hour: start_hour
end_hour: end_hour
title: "`r params$set_title`"
---
<body style="background-color:#ffffff;">
```{r setup, include=FALSE}
start_time <- Sys.time()
# 1. Load Library
library(wpa)
library(dplyr)
library(tidyr)
# 1a. Load auxiliary functions
source("auxiliary.R")
# Glossary
gloss_tb <-
readr::read_csv("glossary.csv")
# 2. Load Data
my_sq_data <- params$wbq
my_em_data <- params$hcq
hrvar <- params$hrvar
mingroup <- params$mingroup
start_hour <- params$start_hour
end_hour <- params$end_hour
intro_toc <- readLines("toc.md")
# Add col checker ----------------------------------------------------------
# If `replacement` is unspecified, it uses `col`
col_checker <- function(x, col, replacement = col){
if(!(col %in% names(x)) & !(replacement %in% names(x))){
# column does not exist at all
# ACTION: DUMMY COLUMN WITH REPLACEMENT
dplyr::mutate(x, !!sym(replacement) := NA) # create dummy column
} else if(col %in% names(x) & !(replacement %in% names(x))){
# column exists in x but not replacement
# ACTION: RENAME
dplyr::rename(x, !!sym(replacement) := col)
} else if(!(col %in% names(x)) & replacement %in% names(x)){
# column does not exists in x but in replacement
# ACTION: RETURN
x
} else if(col %in% names(x) & replacement %in% names(x)){
# column exists in both x and replacement
# ACTION: RETURN
x
} else {
stop("Internal error with conditional.")
}
}
# 3a. Simulate variables for custom Wellbeing query
my_sq_data <-
my_sq_data %>%
# Column checks ----------------------------------------------------------
col_checker(col = "Instant_Message_hours", replacement = "Instant_message_hours") %>%
col_checker(col = "Collaboration_hrs", replacement = "Collaboration_hours") %>%
col_checker(col = "Unscheduled_call_hours", replacement = "Unscheduled_Call_hours") %>%
col_checker(col = "Urgent_email_hours") %>%
col_checker(col = "Urgent_meeting_hours") %>%
col_checker(col = "Weekend_Email", replacement = "Weekend_emails_sent") %>%
col_checker(col = "Weekend_IMs_sent") %>%
col_checker(col = "IMs_sent_same_level") %>%
col_checker(col = "IMs_sent_other_level") %>%
col_checker(col = "Meeting_hours_1on1", replacement = "Intimate_1_on_1_meeting_hours") %>%
col_checker(col = "Meeting_hours_intimate_group",
replacement = "Intimate_group_meeting_hours") %>%
col_checker(col = "IMs_sent", replacement = "Instant_messages_sent") %>%
col_checker(col = "Workweek_span") %>%
# Daily estimates --------------------------------------------------------
mutate(Work_time = Workweek_span / 5) %>% # Average day span
mutate(dailyCollabHours = Collaboration_hours / 5) %>% # Average daily CH
mutate(dailyAfterHours = After_hours_collaboration_hours / 5) %>%
# Urgent collaboration ---------------------------------------------------
# mutate(Urgent_collaboration_hours = Urgent_email_hours) %>%
mutate(Urgent_collaboration_hours = Urgent_meeting_hours + Urgent_email_hours) %>%
mutate(IsUrgent = ifelse(Urgent_collaboration_hours > 0, TRUE, FALSE)) %>%
# Weekend work ------------------------------------------------------------
# mutate(Weekend_work = ifelse(Weekend_Email > 0 | Weekend_Meeting > 0, TRUE, FALSE)) %>%
mutate(Weekend_work = ifelse(Weekend_emails_sent > 0 | Weekend_IMs_sent > 0, TRUE, FALSE)) %>%
group_by(PersonId) %>%
mutate(Frequency_of_weekend_work = 1 / (sum(Weekend_work) / n())) %>% #TODO: Verify logic
mutate(monthly_weekend_work = Frequency_of_weekend_work < (52/12)) %>%
ungroup() %>%
# Two Hour Focus Blocks ---------------------------------------------------
mutate(focus_per = (Total_focus_hours/ Workweek_span)) %>%
mutate(focus_per = ifelse(is.infinite(focus_per), 0, focus_per)) %>%
rename(`% of 2-hour focus block` = "focus_per") %>%
mutate(Total_focus_hours_daily = Total_focus_hours / 5) %>%
# Unscheduled collaboration -----------------------------------------------
mutate(Unscheduled_collaboration_hours_daily = (Unscheduled_Call_hours + Instant_message_hours + Email_hours)/5)
# Values containing groups over minimum group size
mingroup_str <-
my_sq_data %>%
hrvar_count(hrvar = hrvar,
return = "table") %>%
filter(n >= mingroup) %>%
pull(!!sym(hrvar))
# 4. Compute working patterns list and flexibility index data
wp_list <-
my_em_data %>%
workpatterns_classify(
start_hour = start_hour,
end_hour = end_hour,
signals = c("email", "IM"),
return = "list",
hrvar = hrvar)
flex_index_data <-
my_em_data %>%
flex_index(
return = "data",
hrvar = hrvar,
signals = c("email", "IM"),
start_hour = start_hour,
end_hour = end_hour
)
```
```{js, echo=FALSE}
var scale = 'scale(1)';
document.body.style.webkitTransform = scale; // Chrome, Opera, Safari
document.body.style.msTransform = scale; // IE 9
document.body.style.transform = scale; // General
```
```{r child = "db_cover_4.Rmd"}
```
```{r child = "db_1.Rmd"}
```
```{r child = "db_2.Rmd"}
```
```{r child = "db_3.Rmd"}
```
```{r child = "db_4.Rmd"}
```
```{r child = "db_5.Rmd"}
```
```{r child = "db_6.Rmd"}
```
```{r child = "db_7.Rmd"}
```
```{r child = "db_8.Rmd"}
```
```{r child = "db_trends.Rmd"}
```
```{r child = "db_notes.Rmd"}
```
|
/scratch/gouwar.j/cran-all/cranData/wpa/inst/rmd_template/wellbeing/wellbeing_report.Rmd
|
UNlocations <- read.delim(file='UNlocations.txt', comment.char='#')
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/UNlocations.R
|
e0F <- read.delim(file='e0F.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/e0F.R
|
e0M <- read.delim(file='e0M.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/e0M.R
|
migrationF <- read.delim(file='migrationF.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/migrationF.R
|
migrationM <- read.delim(file='migrationM.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/migrationM.R
|
mxF <- read.delim(file='mxF.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/mxF.R
|
mxM <- read.delim(file='mxM.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/mxM.R
|
percentASFR <- read.delim(file='percentASFR.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/percentASFR.R
|
popF <- read.delim(file='popF.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/popF.R
|
popM <- read.delim(file='popM.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/popM.R
|
sexRatio <- read.delim(file='sexRatio.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/sexRatio.R
|
tfr <- read.delim(file='tfr.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2008/data/tfr.R
|
UNlocations <- read.delim(file='UNlocations.txt', comment.char='#')
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/UNlocations.R
|
e0F <- read.delim(file='e0F.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/e0F.R
|
e0F_supplemental <- read.delim(file='e0F_supplemental.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/e0F_supplemental.R
|
e0Fproj <- read.delim(file='e0Fproj.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/e0Fproj.R
|
e0M <- read.delim(file='e0M.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/e0M.R
|
e0M_supplemental <- read.delim(file='e0M_supplemental.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/e0M_supplemental.R
|
e0Mproj <- read.delim(file='e0Mproj.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/e0Mproj.R
|
migrationF <- read.delim(file='migrationF.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/migrationF.R
|
migrationM <- read.delim(file='migrationM.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/migrationM.R
|
mxF <- read.delim(file='mxF.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/mxF.R
|
mxM <- read.delim(file='mxM.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/mxM.R
|
percentASFR <- read.delim(file='percentASFR.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/percentASFR.R
|
popF <- read.delim(file='popF.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/popF.R
|
popM <- read.delim(file='popM.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/popM.R
|
sexRatio <- read.delim(file='sexRatio.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/sexRatio.R
|
tfr <- read.delim(file='tfr.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/tfr.R
|
tfr_supplemental <- read.delim(file='tfr_supplemental.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/tfr_supplemental.R
|
tfrprojHigh <- read.delim(file='tfrprojHigh.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/tfrprojHigh.R
|
tfrprojLow <- read.delim(file='tfrprojLow.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/tfrprojLow.R
|
tfrprojMed <- read.delim(file='tfrprojMed.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2010/data/tfrprojMed.R
|
UNlocations <- read.delim(file='UNlocations.txt', comment.char='#')
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/UNlocations.R
|
e0F <- read.delim(file='e0F.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0F.R
|
e0F_supplemental <- read.delim(file='e0F_supplemental.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0F_supplemental.R
|
e0Fproj <- read.delim(file='e0Fproj.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Fproj.R
|
e0Fproj80l <- read.delim(file='e0Fproj80l.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Fproj80l.R
|
e0Fproj80u <- read.delim(file='e0Fproj80u.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Fproj80u.R
|
e0Fproj95l <- read.delim(file='e0Fproj95l.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Fproj95l.R
|
e0Fproj95u <- read.delim(file='e0Fproj95u.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Fproj95u.R
|
e0M <- read.delim(file='e0M.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0M.R
|
e0M_supplemental <- read.delim(file='e0M_supplemental.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0M_supplemental.R
|
e0Mproj <- read.delim(file='e0Mproj.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Mproj.R
|
e0Mproj80l <- read.delim(file='e0Mproj80l.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Mproj80l.R
|
e0Mproj80u <- read.delim(file='e0Mproj80u.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Mproj80u.R
|
e0Mproj95l <- read.delim(file='e0Mproj95l.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Mproj95l.R
|
e0Mproj95u <- read.delim(file='e0Mproj95u.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/e0Mproj95u.R
|
migrationF <- read.delim(file='migrationF.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/migrationF.R
|
migrationM <- read.delim(file='migrationM.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/migrationM.R
|
mxF <- read.delim(file='mxF.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/mxF.R
|
mxM <- read.delim(file='mxM.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/mxM.R
|
percentASFR <- read.delim(file='percentASFR.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/percentASFR.R
|
popF <- read.delim(file='popF.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popF.R
|
popFprojHigh <- read.delim(file='popFprojHigh.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popFprojHigh.R
|
popFprojLow <- read.delim(file='popFprojLow.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popFprojLow.R
|
popFprojMed <- read.delim(file='popFprojMed.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popFprojMed.R
|
popM <- read.delim(file='popM.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popM.R
|
popMprojHigh <- read.delim(file='popMprojHigh.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popMprojHigh.R
|
popMprojLow <- read.delim(file='popMprojLow.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popMprojLow.R
|
popMprojMed <- read.delim(file='popMprojMed.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popMprojMed.R
|
popproj80l <- read.delim(file='popproj80l.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popproj80l.R
|
popproj80u <- read.delim(file='popproj80u.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popproj80u.R
|
popproj95u <- read.delim(file='popproj95u.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popproj95u.R
|
popprojHigh <- read.delim(file='popprojHigh.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popprojHigh.R
|
popprojLow <- read.delim(file='popprojLow.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/popprojLow.R
|
sexRatio <- read.delim(file='sexRatio.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/sexRatio.R
|
tfr <- read.delim(file='tfr.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/tfr.R
|
tfr_supplemental <- read.delim(file='tfr_supplemental.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/tfr_supplemental.R
|
tfrproj80l <- read.delim(file='tfrproj80l.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/tfrproj80l.R
|
tfrproj80u <- read.delim(file='tfrproj80u.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/tfrproj80u.R
|
tfrproj95l <- read.delim(file='tfrproj95l.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/tfrproj95l.R
|
tfrproj95u <- read.delim(file='tfrproj95u.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/tfrproj95u.R
|
tfrprojHigh <- read.delim(file='tfrprojHigh.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/tfrprojHigh.R
|
tfrprojLow <- read.delim(file='tfrprojLow.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/tfrprojLow.R
|
tfrprojMed <- read.delim(file='tfrprojMed.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2012/data/tfrprojMed.R
|
UNlocations <- read.delim(file='UNlocations.txt', comment.char='#')
|
/scratch/gouwar.j/cran-all/cranData/wpp2015/data/UNlocations.R
|
e0F <- read.delim(file='e0F.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2015/data/e0F.R
|
e0F_supplemental <- read.delim(file='e0F_supplemental.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2015/data/e0F_supplemental.R
|
e0Fproj <- read.delim(file='e0Fproj.txt', comment.char='#', check.names=FALSE)
|
/scratch/gouwar.j/cran-all/cranData/wpp2015/data/e0Fproj.R
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.