Blog Post

Viva Insights Inspiration Library Articles
1 MIN READ

Analyze a Person-to-Person Network

VI_Migration's avatar
VI_Migration
Silver Contributor
Sep 24, 2021

Create an "igraph object" with the p2p query and a corresponding network visualization, with additional features for community detection using the network_p2p() function.

Check out the documentation on Github: https://microsoft.github.io/wpa/reference/network_p2p.html

Published Sep 24, 2021
Version 1.0

2 Comments

  • VI_Migration's avatar
    VI_Migration
    Silver Contributor

    Hi VI_Migration  - this is a great question, and actually can be a great addition to the documentation examples!

    The plots on `igraph` can be best customized with a combination of `ggplot2` and `ggraph`. Here is a simple code example, where this effectively asks `network_p2p()` to export an igraph object and then customize a graph from "scratch" with the `ggplot2` and `ggraph` libraries: 

    # Load libraries
    library(wpa)
    library(tidyverse)
    library(ggraph)
    
    # Simulate a small person-to-person dataset
    p2p_data <- p2p_data_sim(size = 50)
    
    # Return a network igraph object
    p2p_g <-
      p2p_data %>%
      network_p2p(display = "louvain",
                  return = "network")
    
    # Custom chart using `ggplot2` + `ggraph`
    p2p_g %>%
      ggraph::ggraph(layout = "igraph", algorithm = "mds") +
      ggraph::geom_edge_link(colour = "lightgrey", edge_width = 0.05, alpha = 1) +
      ggraph::geom_node_point(aes(colour = !!sym("cluster")),
                              alpha = 0.7,
                              pch = 16) +
      scale_color_manual(values = c("red", "green", "black")) +
      theme_void() +
      theme(
        legend.position = "bottom",
        legend.background = element_rect(fill = "white", colour = "white"),
        
        text = element_text(colour = "black"),
        axis.line = element_blank(),
        panel.grid = element_blank()
      ) +
      labs(caption = paste0("Person to person collaboration example"), # spaces intentional
           y = "",
           x = "")

    This code chunk generates a chart like the below, where the colours have been custom-defined. Since this is `ggplot2`, you can customize the colours in any way you want: 

    The slight disadvantage would the `ggraph` method is that it'll be more intensive to compute for large graphs. However, this may provide a workaround if you test the visualization first with a small graph subset before running it on more data. Does this help? (There could be alternative solutions, but this is the most straightforward one I can think of) 

  • VI_Migration's avatar
    VI_Migration
    Silver Contributor

    Is there a way to easily modify the graphical parameters of the network_p2p() outputs? For example the nodes and edges colors and sizes? When my graph gets simplified due to large size of the data (a year of interactions from 2.5K employees), my output is a little messy and difficult to read. The igraph library seems not to have perfect documentation or community-developed know-how, maybe you are able to share some hints how to prepare beautiful vizes? I am just making my baby-steps in R so any guidance is invaluable!