- Data activity (10 min)
- Introduction to Networks (10 min)
- Building our first networks (20 min)
- Measures of Centrality (15 min)
- Break (5 min)
- IPCC Report Authorship (25 min)
- Final project time (Remainder)
2023-08-10
print.data.frame(groups)
## group 1 group 2 group 3 ## 1 Jun, Ernest Ng Wei Ning, Zhi Yan Tan, Zheng Yang ## 2 Shah, Jainam Su, Barry Tian, Zerui ## 3 Gnanam, Akash Y Gupta, Umang Somyurek, Ecem ## 4 Alsayegh, Aisha E H M I Andrew Yu Ming Xin, Leong, Wen Hou Lester ## group 4 group 5 ## 1 Spindler, Laine Addison Dotson, Bianca Ciara ## 2 Cai, Qingyuan Ramos, Jessica Andria Potestades ## 3 Saccone, Alexander Connor Cortez, Hugo Alexander ## 4 Wan Rosli, Nadia ## group 6 group 7 ## 1 Premkrishna, Shrish Huynh Le Hue Tam, Vivian ## 2 Knutson, Blue C ## 3 Lim, Fang Jan Ng, Michelle ## 4 Widodo, Ignazio Marco Albertini, Federico
igraphNetwork example. From Nykamp DQ, “An introduction to networks”.
Directed Network. From Nykamp DQ, “An introduction to networks”.
Undirected Network. From Nykamp DQ, “An introduction to networks”.
el for “edge list”el <- data.frame(person_1 = c("Lionel", "Frederica", "Garrett", "Lina",
"Sampson", "Garrett", "Frederica", "Lionel",
"Frederica", "Frederica", "Ahmad"),
person_2 = c("Lina", "Charlotte", "Lina", "Sampson",
"Charlotte", "Lionel", "Lina", "Sampson",
"Sampson", "Garrett", "Garrett")) %>%
as.matrix()
# take a look
el
## person_1 person_2 ## [1,] "Lionel" "Lina" ## [2,] "Frederica" "Charlotte" ## [3,] "Garrett" "Lina" ## [4,] "Lina" "Sampson" ## [5,] "Sampson" "Charlotte" ## [6,] "Garrett" "Lionel" ## [7,] "Frederica" "Lina" ## [8,] "Lionel" "Sampson" ## [9,] "Frederica" "Sampson" ## [10,] "Frederica" "Garrett" ## [11,] "Ahmad" "Garrett"
igraph to create a network objectlibrary(igraph) # create network from edge list net <- graph_from_edgelist(el)
library(igraph) # create network from edge list net <- graph_from_edgelist(el, directed = FALSE)
# plot network plot(net)
vertex and edge# customize network plot
plot(net, vertex.size = 30,
vertex.color = "lavender",
vertex.frame.color = NA,
vertex.label.cex = .7,
edge.curved = .05,
edge.arrow.size = .3,
edge.width = .7,
edge.color = "gray1")
ipcc_authors <- read_csv("IPCC_co_authorship.csv",
skip = 1)
library(dplyr) # reorder column names to match rows ipcc_authors %<>% select(order(colnames(.))) # turn dataframe into matrix ipcc_authors %<>% select(-Author) %>% as.matrix()
ipcc_net <- graph_from_adjacency_matrix(ipcc_authors,
mode = "undirected")
plot(ipcc_net, vertex.size = 2,
vertex.color = "lavender",
vertex.frame.color = NA,
vertex.label.cex = .5,
edge.curved = .05,
edge.width = .1,
edge.color = "gray1")
# replace 1s with 0s ipcc_authors[ipcc_authors == 1] = 0 # replace NAs with 0s ipcc_authors[is.na(ipcc_authors)] = 0
# vector of authors who do not collaborate with others
no_colab <- which(apply(ipcc_authors, 1, sum, na.rm = TRUE) == 0)
# then we can remove these from ipcc_authors
ipcc_authors <- ipcc_authors[-no_colab,
-no_colab]
# create network, again
ipcc_net <- graph_from_adjacency_matrix(ipcc_authors,
mode = "undirected")
plot(ipcc_net, vertex.size = 2,
vertex.color = "lavender",
vertex.frame.color = NA,
vertex.label.cex = .5,
edge.curved = .05,
edge.width = .1,
edge.color = "gray1")
V()# add betweenness centrality V(ipcc_net)$betweenness <- betweenness(ipcc_net)
plot(ipcc_net,
vertex.size = V(ipcc_net)$betweenness/max(V(ipcc_net)$betweenness) * 20,
vertex.color = "lavender",
vertex.frame.color = NA,
vertex.label.cex = .5,
edge.curved = .05,
edge.width = .1,
edge.color = "gray1")
print.data.frame(groups)
## group 1 group 2 group 3 ## 1 Jun, Ernest Ng Wei Ning, Zhi Yan Tan, Zheng Yang ## 2 Shah, Jainam Su, Barry Tian, Zerui ## 3 Gnanam, Akash Y Gupta, Umang Somyurek, Ecem ## 4 Alsayegh, Aisha E H M I Andrew Yu Ming Xin, Leong, Wen Hou Lester ## group 4 group 5 ## 1 Spindler, Laine Addison Dotson, Bianca Ciara ## 2 Cai, Qingyuan Ramos, Jessica Andria Potestades ## 3 Saccone, Alexander Connor Cortez, Hugo Alexander ## 4 Wan Rosli, Nadia ## group 6 group 7 ## 1 Premkrishna, Shrish Huynh Le Hue Tam, Vivian ## 2 Knutson, Blue C ## 3 Lim, Fang Jan Ng, Michelle ## 4 Widodo, Ignazio Marco Albertini, Federico
ipcc_authors in your environment)ipcc_authors <- read_csv("IPCC_co_authorship.csv",
skip = 1)
library(dplyr) # reorder column names to match rows ipcc_authors %<>% select(order(colnames(.))) # turn dataframe into matrix ipcc_authors %<>% select(-Author) %>% as.matrix()
# replace 1s with 0s ipcc_authors[ipcc_authors == 1] = 0 # replace NAs with 0s ipcc_authors[is.na(ipcc_authors)] = 0
# vector of authors who do not collaborate with others
no_colab <- which(apply(ipcc_authors, 1, sum, na.rm = TRUE) == 0)
# then we can remove these from ipcc_authors
ipcc_authors <- ipcc_authors[-no_colab,
-no_colab]
igraph objectweighted = TRUE to weight by collaborations# create network, again
ipcc_net <- graph_from_adjacency_matrix(ipcc_authors,
mode = "undirected",
weighted = TRUE)
V()# add betweenness centrality V(ipcc_net)$betweenness <- betweenness(ipcc_net)
# show authors in descending order V(ipcc_net)[order(V(ipcc_net)$betweenness, decreasing = TRUE)]
## + 148/148 vertices, named, from cd68747: ## [1] Shukla Schaeffer Smith ## [4] Edenhofer Price Carraro ## [7] Uerge-Vorsatz Krey Riahi ## [10] Clarke Rogner Lutz ## [13] Kahn-Ribeiro Nakicenovic Winkler ## [16] Hoehne Paltsev Michaelowa ## [19] Strachan Sathaye Faaij ## [22] Hourcade Ravindranath Halsnaes ## [25] Bosetti Zhang Skea ## [28] Den-Elzen Lecocq Fischedick ## + ... omitted several vertices
# plot network
plot(ipcc_net,
edge.width=(E(ipcc_net)$weight)/5,
vertex.size = V(ipcc_net)$betweenness/max(V(ipcc_net)$betweenness) * 20,
vertex.color = "lavender",
vertex.alpha = 0.5,
vertex.frame.color = NA,
vertex.label.cex = .5,
edge.curved = .05,
edge.width = .1,
edge.color = "gray1")
# read in cv data
ipcc_cvs <- read_csv("IPCC_cv.csv")
# define global regions
ipcc_cvs %<>%
mutate(region = case_match(`IPCC representing country (i.e. Country of residence from IPCC doc)`,
# Europe will be green
c("Austria", "Belgium", "Denmark", "Finland",
"France", "Germany", "Greece", "Hungary", "Italy",
"Netherlands", "Norway", "Spain", "Sweden",
"Switzerland", "UK") ~ "green4",
# North America will be red
c("Canada", "USA", "Mexico") ~ "tomato",
# BRICS will be blue
c("Brazil", "Russia", "India", "China",
"South Africa") ~ "steelblue",
# Other countries will be gold
.default = "gold"))
# define country variable V(ipcc_net)$region <- ipcc_cvs$region
vertex.color# plot network
plot(ipcc_net,
edge.width=(E(ipcc_net)$weight)/5,
vertex.size = V(ipcc_net)$betweenness/max(V(ipcc_net)$betweenness) * 20,
vertex.color = V(ipcc_net)$region,
vertex.alpha = 0.5,
vertex.frame.color = NA,
vertex.label.cex = .5,
edge.curved = .05,
edge.width = .1,
edge.color = "gray1")
# add legend
legend(
"bottomright",
legend = c("Europe", "North America", "BRICS", "Other"),
pt.bg = c("green4", "tomato", "steelblue", "gold"),
pch = 21,
cex = 1,
title = "Region"
)
“local network capacities of Lower Ninth Ward residents relative to those of the more affluent Lakeview neighborhood dissipated before, during, and after the disaster to erode the life chances of individual residents and the neighborhood they once constited.” (Elliott, Haney, & Sams-Abiodun, 2010:624)
“For example, if a translocal tie can help one find housing during evacuation, this assistance may be useful only for those who also possess the financial capital needed to travel there and pay market rent; otherwise, such translocal assistance may be much less useful and therefore go unutilized.” (Elliott et al., 2010:630)
networkD3networkD3igraph object to networkd3 objectlibrary(networkD3) # create dataframe for networkD3 ipcc_d3 <- igraph_to_networkD3(ipcc_net, group = V(ipcc_net)$region)
networkD3# set color scale
ColourScale <- 'd3.scaleOrdinal()
.domain(["Europe", "North America", "BRICS", "Other"])
.range(["#07C343", "#D2140C", "#0C4AD2", "#C7D20C"]);'
networkD3forceNetwork() to build interactive networkp <- forceNetwork(Links = ipcc_d3$links,
Nodes = ipcc_d3$nodes,
Group = "group",
height="400px", width="800px",
NodeID = "name",
fontSize = 14,
colourScale = JS(ColourScale),
zoom = TRUE)
networkD3# plot network! p
# read migration data
ca_migration <- read_csv("ca_migration.csv")
## Rows: 28 Columns: 3 ## ── Column specification ──────────────────────────────────────────────────────── ## Delimiter: "," ## chr (2): from, to ## dbl (1): value ## ## ℹ Use `spec()` to retrieve the full column specification for this data. ## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(circlize)
library(stringr)
library(viridis)
# create chord diagram
chordDiagram(ca_migration,
transparency = 0.25,
grid.col = inferno(7),
directional = 1,
direction.type = c("arrows", "diffHeight"),
diffHeight = -0.04,
annotationTrack = "grid",
annotationTrackHeight = c(0.05, 0.1),
link.arr.type = "big.arrow",
link.sort = TRUE,
link.largest.ontop = TRUE)
# Add text and axis
circos.trackPlotRegion(
track.index = 1,
bg.border = NA,
panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
sector.index = get.cell.meta.data("sector.index")
# Add names to the sector.
circos.text(
x = mean(xlim),
y = 2.2,
labels = sector.index,
facing = "bending",
cex = 0.8
)
}
)