--- title: " Your Title" author: "Your Name" date: "4/7/2021" output: html_document: toc: true toc_float: true --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, cache = TRUE) ``` ```{r add_company_logo} # Replace logo with your company logo htmltools::img(src = knitr::image_uri("./your_company_logo_small.png"), alt = 'company_logo', style = 'position:absolute; top:0; right:0; padding:10px') ``` ```{r toc_color, eval = F } ### Add the following HTML text in body of doc itself right between html script tags right below this chunk ### This works with the floating TOC on the upper left and lets you change ### default branding to your company branding. .list-group-item.active, .list-group-item.active:focus, .list-group-item.active:hover { background-color: #007F85; # } ``` ## Introduction Include some basic introductory text here. For example, "This report is a basic descriptive analysis of turnover data collected from X to Y. We analyzed data according to...". Then include some bullet points detailing your analysis elements such as demographics, role, business area or whatever you included. Remember that your real data will need to deal with specific time periods; for simplicity we could say the current dummy data covers several years. * Point 1 * Point 2 * Point 3 **Key Findings** 1. Finding 1 2. Finding 2 3. Finding 3 ```{r libraries} ### Load whatever libraries you need here ### I'm including some of my own to get you started library(inspectdf) # exploratory tools library(psych) # more stats library(tidyverse) # all things tidy like dplyr, ggplot, etc. library(knitr) library(kableExtra) ``` ```{r load_data} ### loading my example data ### you can find this example data here: https://www.hranalytics101.com/wp-content/uploads/2021/01/turnover_calc_youtube-1.csv ### Replace the location and filename info here with your data in the local project folder d <- readr::read_csv("data/Sim_Turnover_Data_HR_Analytics_101_CSV (1).csv") ``` ```{r inspect, eval = F} ### including sample inspection code here for your use ### Run it interactively to explore your data and figure out what you have ### but set the eval to FALSE so this code chunk won't run when creating your ### actual report because the reader doesn't need to see this....this is just for your head(d) summary(d) ``` ## People Overview Include some basic demographics to get the reader oriented to your population. Tables and figures are generally preferrable. ```{r tables1} d %>% mutate_at(vars(role), factor, levels = c("CEO", "VP", "Director", "Manager", "Ind")) %>% {table(.$sex, .$role)} %>% knitr::kable(caption = "Roles by Gender") %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed")) table(d$perf) %>% as.data.frame() %>% dplyr::rename(Performance = Var1, Count = Freq) %>% knitr::kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed")) ``` ```{r tables2, results = F} ### I need some of data changes here ### but I don't necessarily want to show the results ### so I set the results to FALSE # new variables for easier interpretation d$vol_leave2 <- ifelse(d$vol_leave == 1, "depart", "stay") # relabeling d$perf2 <- ifelse(d$perf == 1, "low", ifelse(d$perf == 2, "med", "high")) # relabeling ## converting perf2 to a factor so we can order the values as low-med-high d$perf2 <- factor(d$perf2, levels = c("low", "med", "high")) ## Tables all of our character columns d %>% dplyr::select(where(is.character)) %>% map(table) ``` ```{r mf_by_role} ## Dropping ceo and vps because of small number ## and different career dynamics and making role a factor in the ## order I want d2 <- d %>% dplyr::filter(role %in% c("Ind", "Manager", "Director")) %>% mutate_at(vars(role), factor, levels = c("Ind", "Manager", "Director")) %>% mutate_at(vars(perf), factor, levels = c("1", "2","3")) temp <- d2 %>% group_by(role, sex) %>% dplyr::summarize(n = n()) %>% mutate(perc = n/sum(n)) ggplot(temp, aes(x = sex, y = perc, fill = sex)) + geom_bar(stat = "identity", show.legend = F) + facet_grid(~ role) + scale_fill_hue(l=40) + xlab(label = "") + ylab(label = "") + ylab(label = "Proportion") + ggtitle(label = "Gender by Role") ``` ```{r salary_age} ggplot(d2, aes(x = role, y = age, fill = role)) + geom_boxplot() + scale_fill_hue(l=40) + ggtitle(label = "Age by Role") ggplot(d2, aes(x = role, y = salary, fill = role)) + geom_boxplot() + scale_fill_hue(l=40) + ggtitle(label = "Salary by Role") ``` ## Turnover Breakdown turnover rates by the big pieces: demographics, role, salary, etc. I give an example of one plot with multiple factors followed by a series of simpler breakdowns. I also include barplots along with mosaic plots. Again, nothing is set in stone: test, get feedback, iterate. ### Multi-Factor ```{r multi_factor} # Examples of different multiple factor plots....play with these and # see what might work for you # ggplot(d2, aes(x = age, y = salary, color = vol_leave2, shape = sex)) + # geom_point() + scale_color_manual(values = c('#AE3121', '#007F85')) + # facet_grid(rows = vars(role)) # # d2 %>% dplyr::filter(perf2 == "high") %>% ggplot(aes(x = age, y = salary, color = vol_leave2, shape = sex)) + # geom_point() + scale_color_manual(values = c('#AE3121', '#007F85')) + # facet_grid(rows = vars(role)) d2 %>% dplyr::filter(sex == "Female", role == "Ind", area == "Sales") %>% ggplot(aes(x = perf2, y = salary, color = vol_leave2)) + labs(color = "Departure Status") + geom_jitter(alpha = .6 ) + scale_color_manual(values = c('#AE3121', '#007F85')) + xlab(label = "Performance") + ylab(label = "Salary") + ggtitle(label = "Departure of Females in Sales by Performance") ``` ### Male/ Female ```{r turnover_mf_bar, eval = F} ### Including as example of barplot. Set eval = T to see the result d2 %>% group_by(sex, vol_leave2) %>% summarize(n = n()) %>% group_by(sex) %>% mutate(prop = n/sum(n)) %>% ggplot(aes(x = sex, y = prop, fill = vol_leave2)) + geom_bar(stat = "identity", position = "dodge") + xlab("Gender") + scale_fill_hue(l=40) + ggtitle(label = "Turnover by Gender") + labs(fill = "Departure Status") ``` ```{r turnover_mf_mosaic} ### Mosaic plots offer a nice alternative mosaicplot(sex ~ vol_leave2, data = d2, ylab = "Departure", xlab = "", col = c('#AE3121', '#007F85'), main = "Turnover by Gender") ``` ### Role ```{r turnover_role} d2 %>% group_by(role, vol_leave2) %>% summarize(n = n()) %>% group_by(role) %>% mutate(prop = n/sum(n)) %>% ggplot(aes(x = role, y = prop, fill = vol_leave2)) + geom_bar(stat = "identity", position = "dodge") + scale_fill_hue(l=40) + ggtitle(label = "Turnover by Role") + labs(fill = "Departure Status") + xlab(label = "") + ylab(label = "proportion") ``` ### Salary ```{r salary_turnover} ggplot(d2, aes(x = vol_leave2, y = salary, fill = vol_leave2)) + geom_boxplot() + facet_grid(~role + sex) + scale_fill_hue(l=40) + xlab(label = "") + labs(fill = "Departure Status") ``` ### Performance ```{r turnover_perf} d2 %>% group_by(perf2, vol_leave2, sex) %>% summarize(n = n()) %>% group_by(sex, perf2) %>% mutate(prop = n/sum(n)) %>% ggplot(aes(x = perf2, y = prop, fill = vol_leave2)) + geom_bar(stat = "identity", position = "dodge") + scale_fill_hue(l=40) + ggtitle(label = "Turnover by Performance and Gender") + labs(fill = "Departure Status") + xlab("Performance") + facet_grid(~sex) ``` ```{r perf2_with_mosaic} ### Mosaic plots offer a nice alternative mosaicplot(perf2 ~ vol_leave2, data = d2, ylab = "Departure", xlab = "", col = c('#AE3121', '#007F85'), main = "Turnover by Performance") ``` ## Summary Provide a very short summary statement about what you found. Include some points if it makes sense. * Point 1 * Point 2 * Point 3 ## Next Actions Say what the next actions might be. This could be the next analysis or some specific set of actions. Be thoughtful here. Bullets are always a plus for clarity. * Point 1 * Point 2 * Point 3