Case Studies: Network Analysis in R
Edmund Hart
Instructor
library(HiveR)
library(igraph)
# Create random graph
rand_g <- erdos.renyi.game(18, 0.3, "gnp", directed = TRUE)
# Plot random graph
plot(rand_g, vertex.size = 7)
# Convert to dataframe for hive plots and add weights rand_g_df <- as.data.frame(get.edgelist(rand_g)) rand_g_df$weight <- 1
# Convert to hive object rand_hive <- edge2HPD(edge_df = rand_g_df)
# Set the axis and the radius of each node rand_hive$nodes$axis <- sort(rep(1:3, 6)) rand_hive$nodes$radius <- as.double(rep(1:6, 3))
# See how nodes are modified
rand_hive$nodes
id lab axis radius size color
1 2 1 1 1 black
2 8 1 2 1 black
3 9 1 3 1 black
4 3 1 4 1 black
5 4 1 5 1 black
6 7 1 6 1 black
7 11 2 1 1 black
8 14 2 2 1 black
9 18 2 3 1 black
# See hive plot
plotHive(rand_hive, method = "abs", bkgnd = "white")
# Setting location of each node rand_hive$nodes$axis <- sort(rep(1:3, 6)) rand_hive$nodes$radius <- as.double(rep(1:6, 3))
# Add weights to each edge rand_hive$edges$weight <- as.double( rpois(length(rand_hive$edges$weight), 5) ) # Add color based on edge origination rand_hive$edges$color[rand_hive$edges$id1 %in% 1:6] <- 'red' rand_hive$edges$color[rand_hive$edges$id1 %in% 7:12] <- 'blue' rand_hive$edges$color[rand_hive$edges$id1 %in% 13:18] <- 'green'
# Plot plotHive(rand_hive, method = "abs", bkgnd = "white")
# Create random graph rand_g <- erdos.renyi.game(10, 0.3, "gnp", directed = FALSE) rand_g <- simplify(rand_g)
# Add names to vertices V(rand_g)$name <- LETTERS[1:length(V(rand_g))]
# Create biofabric plot biofbc <- bioFabric(rand_g) bioFabric_htmlwidget(biofbc)
Case Studies: Network Analysis in R