Useful commands or R Markdown Cheat Sheet
Ignacio et al. (2022) Banyard, Hamby, and Grych (2017) Cai et al. (2024) Cano et al. (2020) Cromer et al. (2019) Hong et al. (2018) Ferber and Weller (2022) Callaghan et al. (2019) Chan et al. (2023) Weidacker et al. (2022) Hirshfeld-Becker et al. (2019) Gur et al. (2020) Bram, Gottschalk, and Leeds (2018) Wymbs et al. (2020) Bernstein and McNally (2018) Gildawie, Honeycutt, and Brenhouse (2020) Kuhlman et al. (2023) Kayser et al. (2019) Dvorsky et al. (2019) Kirby et al. (2022) Murphy et al. (2017) Carter, Powers, and Bradley (2020) Ramaiya et al. (2018) Sendzik et al. (2017) Wu, Slesnick, and Murnan (2018) Cornwell et al. (2024) Skinner et al. (2020) Gibbons and Bouldin (2019) Rodman et al. (2019) Higheagle Strong et al. (2020) McRae et al. (2017) Martinez Jr et al. (2022) Vannucci et al. (2019) Noroña-Zhou and Tung (2021) Motsan, Yirmiya, and Feldman (2022) Rich et al. (2019) Krause et al. (2018) Sui et al. (2020) Grych et al. (2020) Vega-Torres et al. (2020) Kliewer and Parham (2019) Griffith, Farrell-Rosen, and Hankin (2023) Siciliano et al. (2023) White et al. (2021) Bettis et al. (2019) Rudolph et al. (2024) Linke et al. (2020) Cornwell et al. (2023) Criss et al. (2017) Koban et al. (2017) Kashdan et al. (2020) Priel et al. (2020) Hannan et al. (2017) Malberg (2023) Tang, Tang, and Gross (2019) Caceres et al. (2024) Gupta, Dickey, and Kujawa (2022) Gee (2022) Khahra et al. (2024) Szoko et al. (2023) Barzilay et al. (2020) Jiang, Paley, and Shi (2022) Xiao et al. (2019) Finkelstein-Fox, Park, and Riley (2018) Sevinc et al. (2019) Blair et al. (2018) Buthmann et al. (2024) Schäfer et al. (2017) Smith and Jen’nan (2024) explored research focusing on various populations and areas to find the effects of several factors like living experience, environment, physical and mental health, and their relationship of emotion regulation and resilience development.
This is where the steps go
#Procedures to decompose an adjacency list into a weighted graph
library(splitstackshape)
library(stringr)
library(igraph)
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
library(networkD3)
library(magrittr)
library(htmlwidgets)
##
## Attaching package: 'htmlwidgets'
## The following object is masked from 'package:networkD3':
##
## JS
library(htmltools)
a<-read.csv("/Users/jinzeyang/Desktop/Fall 2024/Social Networks Analysis/A_Delieverables/US emotion regulation.csv")
#Get Author names
authors<-as.data.frame(a[,1])#"Author.s..ID"])
colnames(authors)<-"AU"
# remove number
authors$AU <- str_remove_all(authors$AU, "[^[\\a-zA-Z ]]")
a1<-cSplit(authors, splitCols = "AU", sep = ";", direction = "wide", drop = TRUE)
class(a1)
## [1] "data.table" "data.frame"
#Matrix and Edgelist
mat <- as.matrix(a1)
dim(mat)
## [1] 70 16
# Combine authors and publications in a matrix
mat <- cbind(a$EID, mat)
edgelist1<-matrix(NA, 1, 2)
for (i in 1:1) {
edgelist11 <- cbind(mat[, i], c(mat[, -c(1:i)]))
edgelist1 <- rbind(edgelist1,edgelist11)
edgelist1<-edgelist1[!is.na(edgelist1[,2]),]
edgelist1<-edgelist1[edgelist1[,2]!="",]
}
dim(edgelist1)
## [1] 407 2
head(edgelist1)
## [,1] [,2]
## [1,] "2-s2.0-85124618928" "Ignacio D.A."
## [2,] "2-s2.0-85010380267" "Banyard V."
## [3,] "2-s2.0-85195804072" "Cai Y."
## [4,] "2-s2.0-85078064575" "Cano M.."
## [5,] "2-s2.0-85066870128" "Cromer K.D."
## [6,] "2-s2.0-85054193257" "Hong F."
# Creating the Graph for future relationship analysis and visualization
g<- graph.data.frame(edgelist1[, 2:1], directed = FALSE)
g
## IGRAPH 8408a0e UN-- 446 407 --
## + attr: name (v/c)
## + edges from 8408a0e (vertex names):
## [1] Ignacio D.A. --2-s2.0-85124618928
## [2] Banyard V. --2-s2.0-85010380267
## [3] Cai Y. --2-s2.0-85195804072
## [4] Cano M.. --2-s2.0-85078064575
## [5] Cromer K.D. --2-s2.0-85066870128
## [6] Hong F. --2-s2.0-85054193257
## [7] Ferber S.G. --2-s2.0-85126246871
## [8] Callaghan B.L. --2-s2.0-85067840050
## + ... omitted several edges
V(g)$type <- V(g)$name %in% edgelist1[ , 2]
table(V(g)$type)
##
## FALSE TRUE
## 70 376
i<-table(V(g)$type)[2]
V(g)$label<-V(g)$name
#Transformations to count number of publications
mat_g2_incidence <- t(get.incidence(g))
dim(mat_g2_incidence)
## [1] 376 70
#summarize connections for authors->:publications and publications->authors
dta <- data.frame(id=rownames(mat_g2_incidence), count=rowSums(mat_g2_incidence))
dta <- dta[order(dta$count, decreasing=T), ]
head(dta)
## id count
## Compas B.E. Compas B.E. 3
## Banyard V. Banyard V. 2
## Gur R.E. Gur R.E. 2
## Cornwell H. Cornwell H. 2
## Grych J. Grych J. 2
## Bettis A.H. Bettis A.H. 2
# Centrality Calculation
cent<-data.frame(bet=betweenness(g, normalized=T, directed = FALSE)/max(betweenness(g, normalized=T, directed = FALSE)),eig=evcent(g)$vector, degree=degree(g, mode="total")/max(degree(g, mode="total")))
head(cent)
## bet eig degree
## Ignacio D.A. 0.000000000 7.864143e-18 0.0625
## Banyard V. 0.003766478 2.841011e-17 0.1250
## Cai Y. 0.000000000 0.000000e+00 0.0625
## Cano M.. 0.000000000 1.915109e-18 0.0625
## Cromer K.D. 0.000000000 1.344740e-18 0.0625
## Hong F. 0.000000000 0.000000e+00 0.0625
tail(cent)
## bet eig degree
## 2-s2.0-85053353883 0.016949153 7.854652e-17 0.1875
## 2-s2.0-85068574235 0.254237288 1.617130e-16 0.6250
## 2-s2.0-85042660960 0.033898305 1.043384e-16 0.2500
## 2-s2.0-85180495536 0.084745763 1.375635e-16 0.3750
## 2-s2.0-84991108157 0.121468927 1.065693e-16 0.3125
## 2-s2.0-85198504223 0.005649718 5.357882e-17 0.1250
#Aggregate centrality score of authors and publications. Separate their centrality.
cent$index <- rowSums(cent)
cent$name<-rownames(cent) #Ids in this case
head(cent);tail(cent)
## bet eig degree index name
## Ignacio D.A. 0.000000000 7.864143e-18 0.0625 0.0625000 Ignacio D.A.
## Banyard V. 0.003766478 2.841011e-17 0.1250 0.1287665 Banyard V.
## Cai Y. 0.000000000 0.000000e+00 0.0625 0.0625000 Cai Y.
## Cano M.. 0.000000000 1.915109e-18 0.0625 0.0625000 Cano M..
## Cromer K.D. 0.000000000 1.344740e-18 0.0625 0.0625000 Cromer K.D.
## Hong F. 0.000000000 0.000000e+00 0.0625 0.0625000 Hong F.
## bet eig degree index name
## 2-s2.0-85053353883 0.016949153 7.854652e-17 0.1875 0.2044492 2-s2.0-85053353883
## 2-s2.0-85068574235 0.254237288 1.617130e-16 0.6250 0.8792373 2-s2.0-85068574235
## 2-s2.0-85042660960 0.033898305 1.043384e-16 0.2500 0.2838983 2-s2.0-85042660960
## 2-s2.0-85180495536 0.084745763 1.375635e-16 0.3750 0.4597458 2-s2.0-85180495536
## 2-s2.0-84991108157 0.121468927 1.065693e-16 0.3125 0.4339689 2-s2.0-84991108157
## 2-s2.0-85198504223 0.005649718 5.357882e-17 0.1250 0.1306497 2-s2.0-85198504223
head(cent)
## bet eig degree index name
## Ignacio D.A. 0.000000000 7.864143e-18 0.0625 0.0625000 Ignacio D.A.
## Banyard V. 0.003766478 2.841011e-17 0.1250 0.1287665 Banyard V.
## Cai Y. 0.000000000 0.000000e+00 0.0625 0.0625000 Cai Y.
## Cano M.. 0.000000000 1.915109e-18 0.0625 0.0625000 Cano M..
## Cromer K.D. 0.000000000 1.344740e-18 0.0625 0.0625000 Cromer K.D.
## Hong F. 0.000000000 0.000000e+00 0.0625 0.0625000 Hong F.
# For authors:
cent$bet[1:i]<-(cent$bet[1:i]/max(cent$bet[1:i]))#*10
cent$eig[1:i]<-cent$eig[1:i]/max(cent$eig[1:i])
cent$degree[1:i]<-cent$degree[1:i]/max(cent$degree[1:i])#*5
summary(cent[1:i,])
## bet eig degree index
## Min. :0.000000 Min. :0.00000 Min. :0.3333 Min. :0.06250
## 1st Qu.:0.000000 1st Qu.:0.00000 1st Qu.:0.3333 1st Qu.:0.06250
## Median :0.000000 Median :0.00000 Median :0.3333 Median :0.06250
## Mean :0.009559 Mean :0.04125 Mean :0.3608 Mean :0.08836
## 3rd Qu.:0.000000 3rd Qu.:0.00000 3rd Qu.:0.3333 3rd Qu.:0.06250
## Max. :1.000000 Max. :1.00000 Max. :1.0000 Max. :0.76754
## name
## Length:376
## Class :character
## Mode :character
##
##
##
#For publications
cent$bet[(i+1):nrow(cent)]<-cent$bet[(i+1):nrow(cent)]/max(cent$bet[(i+1):nrow(cent)])#*20
cent$eig[(i+1):nrow(cent)]<-cent$eig[(i+1):nrow(cent)]/max(cent$eig[(i+1):nrow(cent)])
cent$degree[(i+1):nrow(cent)]<-cent$degree[(i+1):nrow(cent)]/max(cent$degree[(i+1):nrow(cent)])#*10
summary(cent[(i+1):nrow(cent),])
## bet eig degree index
## Min. :0.00000 Min. :0.00000 Min. :0.0625 Min. :0.0625
## 1st Qu.:0.03178 1st Qu.:0.00000 1st Qu.:0.1875 1st Qu.:0.2553
## Median :0.08475 Median :0.00000 Median :0.3438 Median :0.4469
## Mean :0.15125 Mean :0.02803 Mean :0.3634 Mean :0.5427
## 3rd Qu.:0.16667 3rd Qu.:0.00000 3rd Qu.:0.4375 3rd Qu.:0.6110
## Max. :1.00000 Max. :1.00000 Max. :1.0000 Max. :2.5085
## name
## Length:70
## Class :character
## Mode :character
##
##
##
head(cent)
## bet eig degree index name
## Ignacio D.A. 0.000000000 2.139866e-17 0.3333333 0.0625000 Ignacio D.A.
## Banyard V. 0.006493506 7.730509e-17 0.6666667 0.1287665 Banyard V.
## Cai Y. 0.000000000 0.000000e+00 0.3333333 0.0625000 Cai Y.
## Cano M.. 0.000000000 5.211091e-18 0.3333333 0.0625000 Cano M..
## Cromer K.D. 0.000000000 3.659094e-18 0.3333333 0.0625000 Cromer K.D.
## Hong F. 0.000000000 0.000000e+00 0.3333333 0.0625000 Hong F.
# Get maximum centrality
cent$max_cent <- NA
cent$max_cent[1:i] <- cent$eig[1:i] + cent$degree[1:i] + cent$bet[1:i]
cent$max_cent[(i+1):nrow(cent)] <- cent$eig[(i+1):nrow(cent)] + cent$degree[(i+1):nrow(cent)] + cent$bet[(i+1):nrow(cent)]
# Rank by centrality
cent<- cent[order(cent$max_cent, decreasing=T),]
head(cent)
## bet eig degree index
## 2-s2.0-85184577079 0.508474576 1.000000e+00 1.0000000 2.5084746
## 2-s2.0-85165091093 0.418079096 9.622778e-01 0.9375000 2.3178569
## 2-s2.0-85091775089 1.000000000 3.619556e-16 1.0000000 2.0000000
## Compas B.E. 1.000000000 7.054650e-17 1.0000000 0.7675377
## Smaragdi A. 0.008991009 1.000000e+00 0.6666667 0.4977215
## Konrad K. 0.008991009 1.000000e+00 0.6666667 0.4977215
## name max_cent
## 2-s2.0-85184577079 2-s2.0-85184577079 2.508475
## 2-s2.0-85165091093 2-s2.0-85165091093 2.317857
## 2-s2.0-85091775089 2-s2.0-85091775089 2.000000
## Compas B.E. Compas B.E. 2.000000
## Smaragdi A. Smaragdi A. 1.675658
## Konrad K. Konrad K. 1.675658
summary(a$Cited.by)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 4.25 12.50 37.50 39.50 537.00
head(a$EID)
## [1] "2-s2.0-85124618928" "2-s2.0-85010380267" "2-s2.0-85195804072"
## [4] "2-s2.0-85078064575" "2-s2.0-85066870128" "2-s2.0-85054193257"
# Adding attributes
#Citation count or publication count
V(g)$pub_citat_count <- c(dta$count[match(V(g)$label[1:i], dta$id)], a$Cited.by[match(V(g)$label[(i+1):length(V(g)$name)], a$EID)])
summary(V(g)$pub_citat_count)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 1.000 1.000 6.798 1.000 537.000
V(g)$label <- c(paste("Name: ", V(g)$label[1:i], ", Pub. count = ", V(g)$pub_citat_count[1:i], ", Degree = ", degree(g)[1:i], ", Max Centrality (max = 3) = ", round(cent$max_cent[match(V(g)$label[1:i], cent$name)], 3) , sep=""),
paste("EID: ", V(g)$label[(i+1):length(V(g)$name)], ", Citation count = ", V(g)$pub_citat_count[(i+1):length(V(g)$name)], ", Degree = ", degree(g)[(i+1):length(V(g)$name)], ", Max Centrality (max = 3) = ", round(cent$max_cent[match(V(g)$label[(i+1):length(V(g)$name)], cent$name)], 3) , sep=""))
head(V(g)$label)
## [1] "Name: Ignacio D.A., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333"
## [2] "Name: Banyard V., Pub. count = 2, Degree = 2, Max Centrality (max = 3) = 0.673"
## [3] "Name: Cai Y., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333"
## [4] "Name: Cano M.., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333"
## [5] "Name: Cromer K.D., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333"
## [6] "Name: Hong F., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333"
tail(V(g)$label)
## [1] "EID: 2-s2.0-85053353883, Citation count = 29, Degree = 3, Max Centrality (max = 3) = 0.204"
## [2] "EID: 2-s2.0-85068574235, Citation count = 38, Degree = 10, Max Centrality (max = 3) = 0.879"
## [3] "EID: 2-s2.0-85042660960, Citation count = 16, Degree = 4, Max Centrality (max = 3) = 0.284"
## [4] "EID: 2-s2.0-85180495536, Citation count = 0, Degree = 6, Max Centrality (max = 3) = 0.46"
## [5] "EID: 2-s2.0-84991108157, Citation count = 537, Degree = 5, Max Centrality (max = 3) = 0.434"
## [6] "EID: 2-s2.0-85198504223, Citation count = 0, Degree = 2, Max Centrality (max = 3) = 0.131"
links_p<-as.data.frame(cbind(get.edgelist(g)))
links_p$V3<-as.numeric(a$Cited.by)[match(links_p$V2, a$EID)] #V3 citation count
head(links_p)
## V1 V2 V3
## 1 Ignacio D.A. 2-s2.0-85124618928 6
## 2 Banyard V. 2-s2.0-85010380267 95
## 3 Cai Y. 2-s2.0-85195804072 0
## 4 Cano M.. 2-s2.0-85078064575 49
## 5 Cromer K.D. 2-s2.0-85066870128 7
## 6 Hong F. 2-s2.0-85054193257 61
tail(links_p)
## V1 V2 V3
## 402 De Brito S. 2-s2.0-85165091093 5
## 403 Riis V. 2-s2.0-85091775089 112
## 404 De Brito S.A. 2-s2.0-85184577079 0
## 405 Fairchild G. 2-s2.0-85165091093 5
## 406 Elovitz M.A. 2-s2.0-85091775089 112
## 407 Fairchild G. 2-s2.0-85184577079 0
links_p$V4<-a$Title[match(links_p$V2, a$EID)] #publication title
# Making edgelist for interactive visualization
V(g)$name<-1:length(V(g))-1
links<-as.data.frame(cbind(get.edgelist(g)))
links$V1<-as.numeric(as.character(links$V1))
links$V2<-as.numeric(as.character(links$V2))
links$V3 <- links_p$V3
links$V4 <- links_p$V4
str(links)
## 'data.frame': 407 obs. of 4 variables:
## $ V1: num 0 1 2 3 4 5 6 7 8 9 ...
## $ V2: num 376 377 378 379 380 381 382 383 384 385 ...
## $ V3: num 6 95 0 49 7 61 3 61 6 2 ...
## $ V4: chr "Individual, family, and social correlates of flourishing outcomes among youth: Findings from the 2016–2017 Nati"| __truncated__ "Health effects of adverse childhood events: Identifying promising protective factors at the intersection of men"| __truncated__ "general psychopathology factor in Chinese adolescents and its correlation with trans-diagnostic protective psyc"| __truncated__ "Depressive Symptoms and Resilience among Hispanic Emerging Adults: Examining the Moderating Effects of Mindfuln"| __truncated__ ...
head(links)
## V1 V2 V3
## 1 0 376 6
## 2 1 377 95
## 3 2 378 0
## 4 3 379 49
## 5 4 380 7
## 6 5 381 61
## V4
## 1 Individual, family, and social correlates of flourishing outcomes among youth: Findings from the 2016–2017 National Survey of Children's Health
## 2 Health effects of adverse childhood events: Identifying promising protective factors at the intersection of mental and physical well-being
## 3 general psychopathology factor in Chinese adolescents and its correlation with trans-diagnostic protective psycho-social factors
## 4 Depressive Symptoms and Resilience among Hispanic Emerging Adults: Examining the Moderating Effects of Mindfulness, Distress Tolerance, Emotion Regulation, Family Cohesion, and Social Support
## 5 After-school poly-strengths programming for urban teens at high risk for violence exposure
## 6 Childhood maltreatment and perceived stress in young adults: The role of emotion regulation strategies, self-efficacy, and resilience
colnames(links)<-c("source","target", "citation", "title")
# sources: the number of starting point of connection; target: the number of ending point of teh connection
# create a object called group.
nodes <- data.frame(name= V(g)$label, pubs_citation = V(g)$pub_citat_count, groups = ifelse(V(g)$type==1, "Author", "Article"))
head(nodes)
## name
## 1 Name: Ignacio D.A., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## 2 Name: Banyard V., Pub. count = 2, Degree = 2, Max Centrality (max = 3) = 0.673
## 3 Name: Cai Y., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## 4 Name: Cano M.., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## 5 Name: Cromer K.D., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## 6 Name: Hong F., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## pubs_citation groups
## 1 1 Author
## 2 2 Author
## 3 1 Author
## 4 1 Author
## 5 1 Author
## 6 1 Author
summary(nodes$pubs_citation)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 1.000 1.000 6.798 1.000 537.000
{
nodes$group<-NA
nodes$group <-cut(nodes$pubs_citation, c(0,1,3,10,20,max(nodes$pubs_citation)), right=TRUE, include.lowest = TRUE)
table(is.na(nodes$group))
table(nodes$group)
head(nodes[is.na(nodes$group),],20)
nodes$group<-ifelse(is.na(nodes$group), "No Citation", ifelse(nodes$group=="[0,1]", "0 or 1 cit/pub", ifelse(nodes$group=="(1,3]", "2 or 3 cit/pub", ifelse(nodes$group=="(3,10]", "4 to 10 cit/pub", ifelse(nodes$group=="(10,20]", "11 to 20 cit/pub", "Over 20 cit/pub")))))
counts<-data.frame(table(nodes$group))
counts$labels <- paste(counts$Var1, ", N= ", counts$Freq, sep="")
nodes$groups <- counts$labels[match(nodes$group, counts$Var1)]
head(nodes)
}
## name
## 1 Name: Ignacio D.A., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## 2 Name: Banyard V., Pub. count = 2, Degree = 2, Max Centrality (max = 3) = 0.673
## 3 Name: Cai Y., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## 4 Name: Cano M.., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## 5 Name: Cromer K.D., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## 6 Name: Hong F., Pub. count = 1, Degree = 1, Max Centrality (max = 3) = 0.333
## pubs_citation groups group
## 1 1 0 or 1 cit/pub, N= 355 0 or 1 cit/pub
## 2 2 2 or 3 cit/pub, N= 35 2 or 3 cit/pub
## 3 1 0 or 1 cit/pub, N= 355 0 or 1 cit/pub
## 4 1 0 or 1 cit/pub, N= 355 0 or 1 cit/pub
## 5 1 0 or 1 cit/pub, N= 355 0 or 1 cit/pub
## 6 1 0 or 1 cit/pub, N= 355 0 or 1 cit/pub
table(nodes$group)
##
## 0 or 1 cit/pub 11 to 20 cit/pub 2 or 3 cit/pub 4 to 10 cit/pub
## 355 10 35 20
## Over 20 cit/pub
## 26
table(nodes$groups)
##
## 0 or 1 cit/pub, N= 355 11 to 20 cit/pub, N= 10 2 or 3 cit/pub, N= 35
## 355 10 35
## 4 to 10 cit/pub, N= 20 Over 20 cit/pub, N= 26
## 20 26
##########
#Following could not show in docs but I attach the link in the below Question&Answer part
# ColourScale <- 'd3.scaleOrdinal()
# .domain(["0 or 1 cit/pub, N= 355", "11 to 20 cit/pub, N= 10", "2 or 3 cit/pub, N= 35", "4 to 10 cit/pub, N= 20", "Over 20 cit/pub, N= 26"])
# .range(["#ff3397", "#e5ff33", "#F4BB44", "#B2BEB5", "#EE4B2B"]);'
#netviz<-forceNetwork(Links = links, Nodes = nodes,
# Source = 'source', Target = 'target',
# NodeID = 'name',
# Group = "groups", # color nodes by group calculated earlier
# charge = -20, # node repulsion
# linkDistance = JS("function(d) { return d.linkDistance; }"),#JS("function(d){return d.value}"),
# linkWidth = JS("function(d) { return Math.sqrt(d.citation)*4; }"),
# opacity = 0.8,
# Value = "citation",
# Nodesize = 'pubs_citation',
# radiusCalculation = JS("Math.sqrt(d.nodesize*30)+10"),
# zoom = T,
# fontSize=14,
# bounded= F,
# legend= TRUE,
# linkColour = ifelse(links$campus == "NEUNK", "#CCFFFF", ifelse(links$campus == "NEUNL", "#e3eaa7", "#abb2b9")),
# colourScale = JS(ColourScale))
#HTMLaddons <-
"function(el, x) {
d3.select('body').style('background-color', ' #36454F')
d3.selectAll('.legend text').style('fill', 'white')
d3.selectAll('.link').append('svg:title')
.text(function(d) { return 'Number of citations : ' + d.value + ', Title: ' + d.title ; })
var options = x.options;
var svg = d3.select(el).select('svg')
var node = svg.selectAll('.node');
var link = svg.selectAll('link');
var mouseout = d3.selectAll('.node').on('mouseout');
function nodeSize(d) {
if (options.nodesize) {
return eval(options.radiusCalculation);
} else {
return 6;
}
}
d3.selectAll('.node').on('click', onclick)
function onclick(d) {
if (d3.select(this).on('mouseout') == mouseout) {
d3.select(this).on('mouseout', mouseout_clicked);
} else {
d3.select(this).on('mouseout', mouseout);
}
}
function mouseout_clicked(d) {
node.style('opacity', +options.opacity);
link.style('opacity', +options.opacity);
d3.select(this).select('circle').transition()
.duration(750)
.attr('r', function(d){return nodeSize(d);});
d3.select(this).select('text').transition()
.duration(1250)
.attr('x', 0)
.style('font', options.fontSize + 'px ');
}
}
"
## [1] "function(el, x) { \nd3.select('body').style('background-color', ' #36454F')\nd3.selectAll('.legend text').style('fill', 'white') \n d3.selectAll('.link').append('svg:title')\n .text(function(d) { return 'Number of citations : ' + d.value + ', Title: ' + d.title ; })\n var options = x.options;\n var svg = d3.select(el).select('svg')\n var node = svg.selectAll('.node');\n var link = svg.selectAll('link');\n var mouseout = d3.selectAll('.node').on('mouseout');\n function nodeSize(d) {\n if (options.nodesize) {\n return eval(options.radiusCalculation);\n } else {\n return 6;\n }\n }\n\n \nd3.selectAll('.node').on('click', onclick)\n\n function onclick(d) {\n if (d3.select(this).on('mouseout') == mouseout) {\n d3.select(this).on('mouseout', mouseout_clicked);\n } else {\n d3.select(this).on('mouseout', mouseout);\n }\n }\n\n function mouseout_clicked(d) {\n node.style('opacity', +options.opacity);\n link.style('opacity', +options.opacity);\n\n d3.select(this).select('circle').transition()\n .duration(750)\n .attr('r', function(d){return nodeSize(d);});\n d3.select(this).select('text').transition()\n\t\n .duration(1250)\n .attr('x', 0)\n .style('font', options.fontSize + 'px ');\n }\n\n}\n"
#netviz$x$links$value <- links$citation
#netviz$x$links$title <- links$title
#netviz$x$links$linkDistance <- (links$citation)*50 #if want citation inverse #"1-(links$citation)*50" at the end
#onRender(netviz, HTMLaddons)
Answer:
Besides creating the interactive network visualization, we also added publication counts and centrality degrees as attributes in the network.
Without visualization, we can only interpret connection strengths through numbers, which can be vague and subjective. Interactive visualizations, on the other hand, provide a more comprehensive perspective by mapping the network visually. They allow us to explore specific connected groups in detail and retrieve more information about those connections. The visualized network helps us understand how publications on emotion regulation contribute to one another and how authors collaborate on their work. One of the goals of choosing this dataset was to better understand these relationships, and the visualization enabled me to see them more directly and clearly.
Moreover, if we hadn’t added attributes, we could only see publication IDs, author names, and whether they are connected without any further details. By including attributes, we can access more detailed information about the authors, such as their names, publication counts, and centrality measures. Attributes adding allows us to understand how an author’s work contributes to other publications and how their works are interconnected. It also helps us group authors more effectively, enabling us to focus on reading their relevant publications together.