Bare bones function to plot an organisation style dendrogram from a tidygraph object.

plot_org(x, fill_var = "org_depth", df = NULL, is_circular = FALSE,
  is_dendrogram = TRUE, return_tbl_graph = FALSE)

Arguments

x

organisation as a tidygraph object (tidygraph)

fill_var

the variable to use as a fill colour for units. Will either be a metric_id in df or a column in the nodes data frame in the tidygraph object (metric name)

df

a data frame in org_tall_df format ie summarised metrics for the units in the network as generated by calc_summary_df. See orgsurveyr-data-formats for more information. If NULL the fill_var comes from the nodes data frame in the tidygraph object (data frame)

is_circular

whether to make the network circular which is useful for larger organisations (logical)

is_dendrogram

whether to make the network a dendrogram or an icicle/starburst plot (logical)

return_tbl_graph

whether to return the constructed tbl_graph object rather than the plot. This can be useful if a different plot needs to be constructed to that provided. Default FALSE (logical)

Value

ggraph object

Details

Note that the recommended way to plot organisations is using the ggraph package. Some examples of how to do this are included in the vignettes. This simple function is provided as a convenience for new users and to use in examples.

DEV NOTE: in ggplot2 version 3.0.0 tidyeval is available so should be able to use this rather than aes_string

Examples

library(tidygraph) library(dplyr) library(ggraph)
#> Loading required package: ggplot2
set.seed(1236) tg2 <- create_realistic_org(4,3, prob=0.3, delete_units = TRUE) %>% simulate_unit_size tg2
#> # A tbl_graph: 38 nodes and 37 edges #> # #> # A rooted tree #> # #> # Node Data: 38 x 4 (active) #> unit_id org_depth is_leaf unit_size #> <chr> <int> <lgl> <dbl> #> 1 1 0 FALSE 3 #> 2 3 1 FALSE 2 #> 3 4 1 FALSE 3 #> 4 5 1 FALSE 3 #> 5 10 2 FALSE 3 #> 6 11 2 FALSE 2 #> # ... with 32 more rows #> # #> # Edge Data: 37 x 2 #> from to #> <int> <int> #> 1 1 2 #> 2 1 3 #> 3 1 4 #> # ... with 34 more rows
# plot the organisation using the depth of the unit in the organisation as fill colour
# NOT RUN { plot_org(tg2, fill_var='org_depth') #normal dendrogram plot_org(tg2, fill_var='org_depth', is_circular=TRUE) #circular dendrogram # build on ggraph object using ggraph functionality - ie add unit sizes plot_org(tg2, fill_var='org_depth') + geom_node_text(aes(label=unit_size), color='white') # }
# can also include aggregated unit information from calc_summary_df # simulate individual data and summarise tg2_indiv_df <- tg2 %>% simulate_individuals_df() %>% mutate(test_var2 = purrr::map_dbl(individual_id, ~rnorm(1, 20,3))) summary_df <- calc_summary_df(tg2, tg2_indiv_df, NULL, c('test_var', 'test_var2'), TRUE)
#> Using wide data frame format for individual variables
# plot the organisation using the cumulative mean of the individual variables
# NOT RUN { plot_org(x=tg2, fill_var = 'test_var', df=summary_df) plot_org(x=tg2, fill_var = 'test_var2', df=summary_df) # }