Visualizing engagement data

HR Analytics: Exploring Employee Data in R

Ben Teusch

HR Analytics Consultant

Visualizing several variables at once

HR Analytics: Exploring Employee Data in R

The tidyr package

HR Analytics: Exploring Employee Data in R

Using tidyr::gather()

library(tidyr)

data %>%
    gather(columns, 
           key = "key", value = "value")
HR Analytics: Exploring Employee Data in R

Using tidyr::gather()

survey_summary             
# A tibble: 3 x 3
   department average_engagement average_promotions
        <chr>              <dbl>              <dbl>
1 Engineering           3.150884          0.4776275
2     Finance           3.238095          0.5396825
3       Sales           2.807175          0.4910314
survey_summary %>% 
  gather(average_engagement,
         average_promotions,
         key = "key",
         value = "value")
# A tibble: 6 x 3
   department                key     value         
        <chr>              <chr>     <dbl>
1 Engineering average_engagement 3.1508845
2     Finance average_engagement 3.2380952
3       Sales average_engagement 2.8071749
4 Engineering average_promotions 0.4776275
5     Finance average_promotions 0.5396825
6       Sales average_promotions 0.4910314
1 tidyr::gather() has been replaced with tidyr::pivot_longer()
HR Analytics: Exploring Employee Data in R

Adding color to bar charts

survey_gathered <- survey_summary %>% 
  gather(average_engagement, average_promotions, 
         key = "key", value = "value")

ggplot(survey_gathered, aes(key, value, fill = department)) + geom_col()
HR Analytics: Exploring Employee Data in R

Adding color to bar charts

HR Analytics: Exploring Employee Data in R

Side-by-side bar charts

ggplot(survey_gathered, aes(key, value, fill = department)) +
  geom_col(position = "dodge")
HR Analytics: Exploring Employee Data in R

Side-by-side bar charts

HR Analytics: Exploring Employee Data in R

Adding facets

ggplot(survey_gathered, aes(x = key,
                            y = value,
                            fill = department)) +
  geom_col(position = "dodge") +
  facet_wrap(~ key, scales = "free")
HR Analytics: Exploring Employee Data in R

HR Analytics: Exploring Employee Data in R

Let's practice!

HR Analytics: Exploring Employee Data in R

Preparing Video For Download...