視覺化參與度資料

HR 分析:用 R 探索員工資料

Ben Teusch

HR Analytics Consultant

同時視覺化多個變數

HR 分析:用 R 探索員工資料

tidyr 套件

HR 分析:用 R 探索員工資料

使用 tidyr::gather()

library(tidyr)

data %>%
    gather(columns, 
           key = "key", value = "value")
HR 分析:用 R 探索員工資料

使用 tidyr::gather()

survey_summary             
# A tibble: 3 × 3
  department  average_engagement average_promotions
  <chr>                    <dbl>              <dbl>
1 Engineering               3.15              0.478
2 Finance                   3.24              0.540
3 Sales                     2.81              0.491
survey_summary %>% 
  gather(average_engagement,
         average_promotions,
         key = "key",
         value = "value")
# A tibble: 6 × 3
  department  key                value
  <chr>       <chr>              <dbl>
1 Engineering average_engagement 3.15 
2 Finance     average_engagement 3.24 
3 Sales       average_engagement 2.81 
4 Engineering average_promotions 0.478
5 Finance     average_promotions 0.540
6 Sales       average_promotions 0.491
1 tidyr::gather() 已被 tidyr::pivot_longer() 取代。
HR 分析:用 R 探索員工資料

為長條圖加上顏色

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

ggplot(survey_gathered, aes(key, value, fill = department)) + geom_col()
HR 分析:用 R 探索員工資料

為長條圖加上顏色

HR 分析:用 R 探索員工資料

並排長條圖

ggplot(survey_gathered, aes(key, value, fill = department)) +
  geom_col(position = "dodge")
HR 分析:用 R 探索員工資料

並排長條圖

HR 分析:用 R 探索員工資料

加入分面

ggplot(survey_gathered, aes(x = key,
                            y = value,
                            fill = department)) +
  geom_col(position = "dodge") +
  facet_wrap(~ key, scales = "free")
HR 分析:用 R 探索員工資料

HR 分析:用 R 探索員工資料

一起來練習吧!

HR 分析:用 R 探索員工資料

Preparing Video For Download...