knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(DiNeR)

DiNeR (Differential Network Visualization in R) is a library built on top of ggplot meant to visualize comparisons among groups of networks.

source("./DifferentialNetworkVis.R")
library(tidyverse)

Create dummy data

test_df_1 <- data.frame(N1 = c("A","B","C"), N2 = c("A","A","F"), Weight=c(2.78, -5.12, -1.28), Type=c("Enriched", "Depleted", "Depleted"), stringsAsFactors=FALSE)
test_df_2 <- data.frame(N1 = c("E","A","A","H","C","F"), N2 = c("D","B","F","G","A","F"), Weight=c(2.78, -5.12, 1.28, 6.7, 1.9, -8.3), Type=c("Enriched", "Depleted", "Enriched", "Enriched", "Enriched", "Depleted"), stringsAsFactors=FALSE)
test_df_3 <- data.frame(N1 = c("A","B","F","C"), N2 = c("G","A","B","D"), Weight=c(1,2,3,4), Type=c("Enriched", "Enriched", "Enriched", "Enriched"), stringsAsFactors=FALSE)

Creating object

Our basic DiNeR object requires a list of data.frame objects. Each data.frame corresponds to node adjacency within an individual's network.

edge_lists <- lapply(list(test_df_1, test_df_2, test_df_3), function(x){
  return(x[,c("N1", "N2")])
})

print(edge_lists)
diff_network_object <- create_diff_network_object(edge_lists)

print(diff_network_object)

Creating the object just sets up the basic topology for each individual. However, we can also add information about: - Individuals (patient identifiers, diagnosis, age) - Nodes and Edges (labels, weights, classes)

Adding information for each individual is done using the add_individual_features function.

individual_info <- data.frame(Index=c(1,2,3), PatientID=c("Patient 131", "Patient 32", "Patient 203"), Diagnosis=c("Control", "Disease", "Disease"))
diff_network_object = add_individual_features(diff_network_object, individual_info)
diff_network_object = add_individual_features(diff_network_object, data.frame(Age=c(47, 53, 28)))
diff_network_object

We can add edge features using add_edge_features.

edge_feature_list = lapply(list(test_df_1, test_df_2, test_df_3), function(x){
  return(x[,c("Weight", "Type")])
})

diff_network_object = add_edge_features(diff_network_object, edge_feature_list)

diff_network_object

Individual Network Visualization

Using plot individual with no other inputs.

plot_individual(diff_network_object)

The color scheme using the above code will be randomly decided. We can, however, add our own color scheme.

colors <- data.frame(high=c("#191970", "#ADD8E6", "#7FFFD4"), low=c("#9A2A2A", "#FAA0A0", "#2AAA8A"))
plot_individual(diff_network_object, colors=colors)

We can also use lapply to run this on all of our data using the idx parameter.

lapply(1:3, function(i){
  plot_individual(diff_network_object, idx=i, colors=colors)
})

More comparisons across individuals

Consensus edge plots allow us to see the occurrence of edges

consensus_edge(diff_network_object)

Pie charts

Pie charts for one group

make_piecharts(diff_network_object, edge_feature="Type")

We can also create an additional visualization for multiple groups

make_piecharts_by_group(diff_network_object, edge_feature="Type", group_label="Diagnosis")


morganoneka/DiNeR documentation built on May 30, 2022, 4:12 p.m.