knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-" ) library(tidygraph, quietly = TRUE) library(ggraph, quietly = TRUE) library(dplyr, quietly = TRUE) library(orgsurveyr, quietly = TRUE)
The goal of orgsurveyr
is to facilitate the use of Thomas Lin Pedersen's excellent tidygraph
and ggraph
packages with organisational information used by many Human Resources departments, in particular employee surveys.
You can install orgsurveyr from github with:
# install.packages("devtools") devtools::install_github("ukgovdatascience/orgsurveyr", build_vignettes = TRUE)
There is also infrastructure within the repo to install and run orgsurveyr within Docker. See the section at the end of this help file for details but essentially you clone the repo and type make run
. More help is available with make help
.
An organisation is a very basic type of network known as a tree. The tidygraph
package lets us simulate and represent a tree structure as follows:
tg <- tidygraph::create_tree(13,3) tg
The ggraph
package can be used to plot networks with the familiar ggplot2
syntax. Below the simulated organisation is plotted as a dendrogram:
ggraph(tg, 'dendrogram') + geom_edge_diagonal() + geom_node_point(size=5) + theme_bw()
The orgsurveyr
package provides detailed vignettes, convenience functions, shiny apps and example data to help HR analysts make use of the ggraph
and tidygraph
packages in the analysis of organisation data.
A realistic organisation can be simulated and plotted:
set.seed(1236) tg2 <- create_realistic_org(4,3, prob=0.3) plot_org(tg2)
Individual level data also be simulated first by simulating the number of individuals in unit:
tg3 <- simulate_unit_size(tg2) tg3
Followed by simulating the individuals and any additional variables. The commands can be piped as per tidyverse convention:
tg3_individuals_df <- tg3 %>% simulate_individuals_df() %>% mutate(test_var2 = purrr::map_dbl(individual_id, ~rnorm(1, 20,3))) tg3_individuals_df
The individual data is aggregated at the unit level. This can be either be just those individuals associated with an organisational unit or (more usefully) a cumulative aggregation involving all individuals that are part of that unit and any units below it in the organisation:
summary_df <- calc_summary_df(tg=tg3, df=tg3_individuals_df, selected_vars=c('test_var', 'test_var2'), is_cumulative=TRUE) summary_df
The aggregated data can be plotted on the dendrogram:
plot_org(tg3, fill_var = 'test_var', summary_df)
Larger organisations can be represented as starburst plots:
set.seed(1236) tg4 <- create_realistic_org(5,5, prob=0.3) %>% simulate_unit_size() tg4_individuals_df <- tg4 %>% simulate_individuals_df() %>% mutate(test_var2 = purrr::map_dbl(individual_id, ~rnorm(1, 20,3))) tg4_summary_df <- calc_summary_df(tg=tg4, df=tg4_individuals_df, selected_vars=c('test_var', 'test_var2'), is_cumulative=TRUE) plot_org(tg4, fill_var = 'test_var', df = tg4_summary_df, is_circular = TRUE, is_dendrogram = FALSE) + scale_fill_gradientn(colours=RColorBrewer::brewer.pal(11, 'PiYG'))
An interactive visualisation in shiny can be launched:
orgviz(tg=tg3, df=summary_df)
The git repository contains infrastructure for installing and running orgsurveyr within Docker. This is useful if you quickly and easily want to try out the package before installing it, and is also useful for trying out the shiny apps.
First clone the git repository to your local machine:
git clone https://github.com/ukgovdatascience/orgsurveyr.git
Then from within the repo type make run
. This will:
To stop and remove the Docker container type make remove
. More help is available by typing make help
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.