-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08082023_two_mode_network_simplified.R
34 lines (29 loc) · 1.45 KB
/
08082023_two_mode_network_simplified.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(igraph)
df_two_mode_10 <- read.csv('two_mode_10.csv', row.names = 1)
df_two_mode_10 <- df_two_mode_10[,!colnames(df_two_mode_10) %in% "pol"]
print(paste("There are", nrow(df_two_mode_10), "items."))
df_two_mode_10_simple <- df_two_mode_10[rowSums(df_two_mode_10) > 0,]
print(paste(nrow(df_two_mode_10_simple), "are kept for network visualization."))
# How many rows in difference?
print(nrow(df_two_mode_10) - nrow(df_two_mode_10_simple))
two_mode_10_graph <- graph_from_incidence_matrix(as.matrix(df_two_mode_10_simple))
# How many nodes?
V_count <- length(V(two_mode_10_graph))
# Confirms that column names (features) are among the node names
colnames(df_two_mode_10) %in% V(two_mode_10_graph)$name
# Confirms that row names (ids) are among the node names
rownames(df_two_mode_10) %in% V(two_mode_10_graph)$name
# V()$type returns FALSE or TRUE, FALSE are the row names
table(V(two_mode_10_graph)$type)
##### VISUALIZATION #####
#### LABELS ####
# default no node labels
V(two_mode_10_graph)$label <- ""
# show feature labels
V(two_mode_10_graph)[V(two_mode_10_graph)$type == T]$label <- V(two_mode_10_graph)[V(two_mode_10_graph)$type == T]$name
#### COLOR ####
V(two_mode_10_graph)$color <- c("orange","lightsteelblue")[V(two_mode_10_graph)$type + 1]
#### SIZE ####
V(two_mode_10_graph)$size <- c(2,20)[V(two_mode_10_graph)$type + 1]
#### Visualize ####
plot(two_mode_10_graph, vertex.frame.color = NA, vertex.label.cex = 1, vertex.label.font = 2, layout = layout_nicely)