shops <- trial%*%t(trial)
# shop-by-shop matrix
shopnet <- graph_from_adjacency_matrix(shops, mode="undirected",
diag = FALSE, weighted = TRUE) # graph object of shop-by-shop network
# flavor-by-flavor matrix showing the number of shops co-supporting each pair of flavors
flavors <- t(trial)%*%(trial) # pre-multiply the transpose by the original matrix to get a flavor preference-by-flavor preference matrix with weighted ties showing the number of shops they share in common
flavornet <- graph_from_adjacency_matrix(flavors, mode = "undirected",
diag = FALSE, weighted = TRUE) # graph object of flavor-by-flavor network
id <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24) # create node ids
# a graph object of the original two-mode data set
trialnet <- graph_from_biadjacency_matrix(trial) # graph object from original two-mode matrix
# visualize all three graph objects and include edge weights when appropriate (use a 1x3 plot space)
id <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24) # create node ids
mode <- c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2) # create mode membership
trial_nodes <- data.frame(id, mode) # create node data frame to differentiate modes
par(mfrow=c(1,3), mar=c(4,2,4,2), mgp=c(2,0.5,0))
plot(trialnet, vertex.label.cex=.6, vertex.label.color="black", vertex.size=8,
vertex.color=ifelse(trial_nodes[V(trialnet), 2] == 1, "lightgray", "lightblue"),
vertex.frame.color="NA", vertex.label.dist=2)
plot(flavornet, vertex.label.cex=.6, vertex.label.color="black", vertex.size=8,
vertex.color=ifelse(trial_nodes[V(trialnet), 2] == 1, "lightgray", "lightblue"),
vertex.frame.color="NA", vertex.label.dist=2)
plot(shopnet, vertex.label.cex=.6, vertex.label.color="black", vertex.size=8,
vertex.color=ifelse(trial_nodes[V(trialnet), 2] == 1, "lightgray", "lightblue"),
vertex.frame.color="NA", vertex.label.dist=2)
Table 1. Displays the centrality of flavors using a betweenness
measurement.
Based on Table 1, the ube flavor has the highest betweenness score,
meaning that ube seems to be a connecting flavor between the bubble tea
shops. In contrast, on the other side of the spectrum is the mango
flavor with the lowest betweenness score, meaning that mango wasn’t a
very connecting flavor between the bubble tea shops.