Creating the environment

library(tidyverse)
library(tidygraph)
library(igraph)
library(bibliometrix)
library(tosr)
library(here)
library(lubridate)
# library(sjrdata)
library(openxlsx)
library(zoo)
library(RSQLite)
library(journalabbr)
library(ggraph)
library(openxlsx)
library(XML)
library(plyr)
library(readxl)
source("verbs.R")
windowsFonts("Times" = windowsFont("Times"))
windowsFonts("Times New Roman" = windowsFont("Times New Roman"))

giant.component <- function(graph) {
  cl <- igraph::clusters(graph)
  igraph::induced.subgraph(graph, 
                           which(cl$membership == which.max(cl$csize)))
}

Data getting

wos_scopus <-
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=1155770196")

wos <-
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=153133772")  # create dataframe from wos file

scopus <-
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=816542007")

reference_df <- 
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=271695740")

journal_df <- 
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=551732174")

author_df <- 
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=329776078")

figure_1_data <- 
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=537653088")

TC_all <- 
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=666252552")

table_2_country <- #table_2_country
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=1568443838")

figure_2_country_wos_scopus <- #figure_2_country_wos_scopus
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=2129383489")

figure_2_country_wos_scopus_1 <- #figure_2_country_wos_scopus_1
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=448937534") |> 
  tidygraph::as_tbl_graph(directed = FALSE) |> 
  activate(nodes) |> 
  dplyr::mutate(community = tidygraph::group_louvain(),
                degree = tidygraph::centrality_degree(),
                community = as.factor(community))
# 
table_3_journal  <-  
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=90932600")
# 
table_4_authors  <- #table_4_authors
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=103155313")
# 
AU_CO_links <-
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=1910928980")

tos <- 
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=765541939")

edges_tos <- 
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=326532588")

nodes_tos <- 
  read_csv("https://docs.google.com/spreadsheets/d/181XJcP5krbj5VaP15rCVJQQAkv5SpDAm9DaNbwKUfJo/export?format=csv&gid=1327949338")

Resutls

Scientometric Analysis

3.1 Scientific Production

Figure 1a - Scopus + WoS

figure_1a <- 
  figure_1_data |> 
  pivot_longer(!PY, names_to = "ref_type", values_to = "n") |> 
  filter(ref_type != "total") |> 
  ggplot(aes(x = factor(PY), 
             y = n, 
             fill = ref_type)) +
  geom_bar(stat = "identity", 
           position = "dodge") +
  geom_text(aes(label = n),
            vjust = -0.3,
            position = position_dodge(0.9),
            size = 3,
            family = "Times") +
  scale_fill_manual(values = c("springgreen3",
                               "orange3")) +
  theme(text = element_text(family = "Times",
                            face = "bold",
                            size =12),
        panel.background = element_rect(fill = "white"),
        legend.position = "bottom",
        legend.title = element_text(size = 0),
        axis.text.x = element_text(face = "bold", 
                                   angle = 45, 
                                   vjust = 0.5),
        axis.line = element_line(color = "black", 
                                 size = 0.2)) +
  labs(y = "Number of publications", 
       x = "Year") 

figure_1a

Figure 1b - Total production

figure_1b <- 
  figure_1_data |> 
  ggplot(aes(x = PY, y = total)) +
  geom_line(stat = "identity", color = "red") +
  geom_point(stat = "identity", color = "red") +
  scale_x_continuous(breaks = seq(2000, year(today()) - 1, by = 1)) +
  geom_text(aes(label = total),
            vjust = -0.3,
            position = position_dodge(0.9),
            size = 3,
            family = "Times", 
            color = "red") +
  scale_fill_manual(values = c("springgreen3",
                               "orange3")) +
  theme(text = element_text(family = "Times",
                            face = "bold",
                            size =12),
        panel.background = element_rect(fill = "white"),
        legend.position = "bottom",
        legend.title = element_text(size = 0),
        axis.text.x = element_text(face = "bold", 
                                   angle = 45, 
                                   vjust = 0.5),
        axis.line = element_line(color = "black", 
                                 size = 0.2)) +
  labs(y = "Number of total publications", 
       x = "Year") 
figure_1b

Figure 1c - Total Citations

figure_1c <- 
  TC_all |> 
  ggplot(aes(x = PY , y = TC_sum_all)) +
  geom_line(stat = "identity", color = "purple") +
  geom_point(color = "purple") +
  scale_x_continuous(breaks = seq(2000, year(today()) - 1 , by = 1)) +
  geom_text(aes(label = TC_sum_all),
            vjust = -0.3,
            position = position_dodge(0.9),
            size = 3,
            family = "Times", 
            color = "purple") +
  scale_fill_manual(values = c("springgreen3",
                               "orange3")) +
  theme(text = element_text(family = "Times",
                            face = "bold",
                            size =12),
        panel.background = element_rect(fill = "white"),
        legend.position = "bottom",
        legend.title = element_text(size = 0),
        axis.text.x = element_text(face = "bold", 
                                   angle = 45, 
                                   vjust = 0.5),
        axis.line = element_line(color = "black", 
                                 size = 0.2)) +
  labs(y = "Number of citations", 
       x = "Year") 
figure_1c

3.2 Country analysis

Table 2 - Country production

table_2_country |>
  DT::datatable(class = "cell-border stripe", 
                rownames = F, 
                filter = "top", 
                editable = FALSE, 
                extensions = "Buttons", 
                options = list(dom = "Bfrtip",
                               buttons = c("copy",
                                           "csv",
                                           "excel", 
                                           "pdf", 
                                           "print")))

Figure 2 - Country Collaboration

# figure_2 <- 
#   figure_2_country_wos_scopus_1 |>
#   ggraph(layout = "graphopt") +
#   geom_edge_link(aes(width = weight),
#                  colour = "lightgray") +
#   scale_edge_width(name = "Link strength") +
#   geom_node_point(aes(color = community, 
#                       size = degree)) +
#   geom_node_text(aes(label = name), repel = TRUE) +
#   scale_size(name = "Degree") +
#   # scale_color_binned(name = "Communities") +
#   theme_graph()
# 
# figure_2

figure_2 <- 
  figure_2_country_wos_scopus_1 |>
  activate(edges) |> 
  dplyr::rename(weight = n) |> 
  ggraph(layout = "graphopt") +
  geom_edge_link(aes(width = weight),
                 colour = "lightgray") +
  scale_edge_width(name = "Link strength") +
  geom_node_point(aes(color = community, 
                      size = degree)) +
  geom_node_text(aes(label = name), repel = TRUE) +
  scale_size(name = "Degree") +
  # scale_color_binned(name = "Communities") +
  theme_graph()

figure_2
## Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.
## Warning: ggrepel: 4 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps

# country_collab_graphml_nodes <- 
#   figure_2_country_wos_scopus_1 |> 
#   activate(nodes) |> 
#   as_tibble() |> 
#   dplyr::rename(author = name) |> 
#   rownames_to_column("name")
# 
# country_collab_graphml_edges <- 
#   figure_2_country_wos_scopus_1 |> 
#   activate(edges) |> 
#   as_tibble() 
# 
# AU_CO_weighted_TM <- 
#   graph_from_data_frame(d = country_collab_graphml_edges, 
#                         directed = FALSE, 
#                         vertices = country_collab_graphml_nodes)
# 
# write_graph(AU_CO_weighted_TM, "AU_CO_weighted_TM.graphml", "graphml") # Export author co-citation graph

Figure 2a - Country Collaboration

figure_2a <- 
  figure_2_country_wos_scopus_1 |> 
  activate(nodes) |> 
  data.frame() |> 
  group_by(community) |> 
  dplyr::count(community, sort = TRUE) |> 
  slice(1:10) |>  
  ggplot(aes(x = reorder(community, n), y = n)) +
  geom_point(stat = "identity") +
  geom_line(group = 1) + 
  # geom_text(label = as.numeric(community),
  #           nudge_x = 0.5,
  #           nudge_y = 0.5,
  #           check_overlap = T) +
  labs(title = "Communities by size", 
       x = "communities", 
       y = "Countries") +
  theme(text = element_text(color = "black",
                            face = "bold",
                            family = "Times New Roman"),
        plot.title = element_text(size = 25),
        panel.background = element_rect(fill = "white"), 
        axis.text.y = element_text(size = 15, 
                                   colour = "black"),
        axis.text.x = element_text(size = 15,
                                   colour = "black"),
        axis.title.x = element_text(size = 20),
        axis.title.y = element_text(size = 20)) 

figure_2a

Figure 2b Longitudinal data of AU_CO

# Create a dataframe with links 
figure_2c_edges <- 
  figure_2_country_wos_scopus |>
  dplyr::filter(from != to) |> 
  tidygraph::as_tbl_graph() |> 
  activate(edges) |> 
  as_tibble() |> 
  dplyr::select(year = PY) |> 
  dplyr::count(year) |> 
  dplyr::filter(year >= 2000,
                year <= 2020) |> 
  dplyr::mutate(percentage = n/max(n)) |> 
  dplyr::select(year, percentage)
# Create a data frame with author and year 
figure_2c_nodes <- # 21 row 
  figure_2_country_wos_scopus |>
  dplyr::filter(from != to) |> 
  tidygraph::as_tbl_graph() |> 
  activate(edges) |> 
  as_tibble() |> 
  dplyr::select(CO = from, 
                year = PY) |>
  bind_rows(figure_2_country_wos_scopus |>  
              tidygraph::as_tbl_graph() |> 
              tidygraph::activate(edges) |> 
              tidygraph::as_tibble() |> 
              dplyr::select(CO = to, 
                            year = PY)) |> 
  unique() |> 
  dplyr::group_by(CO) |> 
  dplyr::slice(which.min(year)) |>
  dplyr::ungroup() |> 
  dplyr::select(year) |> 
  dplyr::group_by(year) |> 
  dplyr::count(year) |> 
  dplyr::filter(year >= 2000,
                year <= 2020) |> 
  dplyr::ungroup() |> 
  dplyr::mutate(percentage = n / max(n)) |> 
  select(year, percentage)

plotting figure 2b

figure_4b <- 
  figure_2c_nodes |> 
  mutate(type = "nodes") |> 
  bind_rows(figure_2c_edges |> 
              mutate(type = "links")) |> 
  ggplot(aes(x = year, 
             y = percentage, 
             color = type)) +
  geom_point() +
  geom_line() +
  theme(legend.position = "right", 
        text = element_text(color = "black", 
                            face = "bold",
                            family = "Times"),
        plot.title = element_text(size = 25),
        panel.background = element_rect(fill = "white"), 
        axis.text.y = element_text(size = 15, 
                                   colour = "black"),
        axis.text.x = element_text(size = 15,
                                   colour = "black", 
                                   angle = 45, vjust = 0.5
        ),
        axis.title.x = element_text(size = 20),
        axis.title.y = element_text(size = 20),
        legend.text = element_text(size = "15"), 
        legend.title = element_blank()) +
  labs(title = "Nodes and links through time", 
       y = "Percentage") +
  scale_y_continuous(labels = scales::percent) +
  scale_x_continuous(breaks = seq(2000, 2020, by = 1))

figure_4b

3.3 Journal Analysis

Table 3 Most productive journals

table_3_journal |> 
  arrange(desc(total)) |> 
    DT::datatable(class = "cell-border stripe", 
                rownames = F, 
                filter = "top", 
                editable = FALSE, 
                extensions = "Buttons", 
                options = list(dom = "Bfrtip",
                               buttons = c("copy",
                                           "csv",
                                           "excel", 
                                           "pdf", 
                                           "print")))

Figure 3 Journal Citation Network

Creating the graph object

journal_citation_graph_weighted_tbl_small <- 
  journal_df |> 
  dplyr::select(JI_main, JI_ref) |> 
  dplyr::group_by(JI_main, JI_ref) |> 
  dplyr::count() |> 
  dplyr::rename(weight = n) |> 
  as_tbl_graph(directed = FALSE) |> 
  # convert(to_simple) |> 
  activate(nodes) |> 
  dplyr::mutate(components = tidygraph::group_components(type = "weak"))  |> 
  dplyr::filter(components == 1) |> 
  activate(nodes) |> 
  dplyr::mutate(degree = centrality_degree(),
                community = tidygraph::group_louvain()) |> 
  dplyr::select(-components) |> 
  dplyr::filter(degree >= 1)
# activate(edges) |>
# dplyr::filter(weight != 1)

communities <- 
  journal_citation_graph_weighted_tbl_small |> 
  activate(nodes) |> 
  data.frame() |> 
  dplyr::count(community, sort = TRUE) |> 
  dplyr::slice(1:10) |> 
  dplyr::select(community) |> 
  dplyr::pull()
# Filtering biggest communities 
journal_citation_graph_weighted_tbl_small_fig <- 
  journal_citation_graph_weighted_tbl_small |> 
  activate(nodes) |> 
  dplyr::filter(community %in% communities)

Selecting nodes to show

jc_com_1 <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[1]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com_2 <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[2]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com_3 <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[3]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com_4 <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[4]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com_5 <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[5]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com_6 <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[6]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com_7<- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[7]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com_8 <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[8]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com_9 <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[9]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com_10 <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(community == communities[10]) |> 
  dplyr::mutate(degree = centrality_degree()) |> 
  dplyr::arrange(desc(degree)) |> 
  dplyr::slice(1:10) |> 
  data.frame() |> 
  dplyr::select(name)
jc_com <- 
  jc_com_1 |> 
  bind_rows(jc_com_2,
            jc_com_3,
            # jc_com_4,
            # jc_com_5,
            # jc_com_6,
            # jc_com_7,
            # jc_com_8,
            # jc_com_9,
            # jc_com_10
  )

Figure 3a Journal Citation

figure_3a <- 
  journal_citation_graph_weighted_tbl_small_fig |> 
  activate(nodes) |> 
  dplyr::filter(name %in% jc_com$name) |>
  dplyr::mutate(degree = centrality_degree(),
                community = factor(community)) |> 
  dplyr::filter(degree != 0) |> 
  ggraph(layout = "graphopt") +
  geom_edge_link(aes(width = weight),
                 colour = "lightgray") +
  scale_edge_width(name = "Link strength") +
  geom_node_point(aes(color = community, 
                      size = degree)) +
  geom_node_text(aes(label = name), repel = TRUE) +
  scale_size(name = "Degree") +
  # scale_color_binned(name = "Communities") +
  theme_graph()
figure_3a

Figure 3b clusters

figure_3b <- 
  journal_citation_graph_weighted_tbl_small |> 
  activate(nodes) |> 
  data.frame() |> 
  dplyr::select(community) |> 
  dplyr::count(community, sort = TRUE) |> 
  dplyr::slice(1:10) |> 
  ggplot(aes(x = reorder(community, n), y = n)) +
  geom_point(stat = "identity") +
  geom_line(group = 1) + 
  # geom_text(label = as.numeric(community),
  #           nudge_x = 0.5,
  #           nudge_y = 0.5,
  #           check_overlap = T) +
  labs(title = "Communities by size", 
       x = "communities", 
       y = "Journals") +
  theme(text = element_text(color = "black",
                            face = "bold",
                            family = "Times"),
        plot.title = element_text(size = 25),
        panel.background = element_rect(fill = "white"), 
        axis.text.y = element_text(size = 15, 
                                   colour = "black"),
        axis.text.x = element_text(size = 15,
                                   colour = "black"),
        axis.title.x = element_text(size = 20),
        axis.title.y = element_text(size = 20)) 
figure_3b

3.2 Author Analysis

Table 4

table_4_authors |> 
    DT::datatable(class = "cell-border stripe", 
                rownames = F, 
                filter = "top", 
                editable = FALSE, 
                extensions = "Buttons", 
                options = list(dom = "Bfrtip",
                               buttons = c("copy",
                                           "csv",
                                           "excel", 
                                           "pdf", 
                                           "print")))

Creating the ASN - graph object

author_network_time <- 
  author_df |> 
  tidygraph::as_tbl_graph(directed = FALSE) |> 
  activate(nodes) |> 
  dplyr::mutate(components = tidygraph::group_components(type = "weak")) |> 
  dplyr::filter(components == 1) |> 
  dplyr::mutate(degree = centrality_degree(),
                community = as.factor(group_louvain()))

author_network <- 
  author_df |> 
  dplyr::select(-PY) |> 
  dplyr::group_by(from, to) |> 
  dplyr::count() |> 
  dplyr::rename(weight = n) |> 
  tidygraph::as_tbl_graph(directed = FALSE) |> 
  activate(nodes) |> 
  dplyr::mutate(components = tidygraph::group_components(type = "weak")) |> 
  dplyr::filter(components == 1) |> 
  dplyr::mutate(degree = centrality_degree(),
                community = as.factor(group_louvain()))

Figure 4a clusters of each community

figure_4a <- 
  author_network |> 
  activate(nodes) |> 
  data.frame() |> 
  dplyr::count(community) |>
  slice(1:10) |>  
  ggplot(aes(x = reorder(community, n), y = n)) +
  geom_point(stat = "identity") +
  geom_line(group = 1) + 
  # geom_text(label = as.numeric(community),
  #           nudge_x = 0.5,
  #           nudge_y = 0.5,
  #           check_overlap = T) +
  labs(title = "Communities by size", 
       x = "communities", 
       y = "Authors") +
  theme(text = element_text(color = "black",
                            face = "bold",
                            family = "Times"),
        plot.title = element_text(size = 25),
        panel.background = element_rect(fill = "white"), 
        axis.text.y = element_text(size = 15, 
                                   colour = "black"),
        axis.text.x = element_text(size = 15,
                                   colour = "black"),
        axis.title.x = element_text(size = 20),
        axis.title.y = element_text(size = 20)) 

figure_4a

Figure 4b Longitudinal data of ASN

# Create a dataframe with links 
fig_1c_edges <- 
  author_network_time |>
  activate(edges) |> 
  as_tibble() |> 
  dplyr::select(year = PY) |> 
  dplyr::count(year) |> 
  dplyr::filter(year >= 2000,
                year <= 2020) |> 
  dplyr::mutate(percentage = n/max(n)) |> 
  dplyr::select(year, percentage)
# Create a data frame with author and year 
fig_1c_nodes <- # 21 row 
  author_network_time |>
  activate(edges) |> 
  as_tibble() |> 
  dplyr::select(author = from, 
                year = PY) |>
  bind_rows(author_network_time |> 
              activate(edges) |> 
              as_tibble() |> 
              dplyr::select(author = to, 
                            year = PY)) |> 
  unique() |> 
  dplyr::group_by(author) |> 
  dplyr::slice(which.min(year)) |>
  dplyr::ungroup() |> 
  dplyr::select(year) |> 
  dplyr::group_by(year) |> 
  dplyr::count(year) |> 
  dplyr::filter(year >= 2000,
                year <= 2020) |> 
  dplyr::ungroup() |> 
  dplyr::mutate(percentage = n / max(n)) |> 
  select(year, percentage)

plotting figure 4b

figure_4b <- 
  fig_1c_nodes |> 
  mutate(type = "nodes") |> 
  bind_rows(fig_1c_edges |> 
              mutate(type = "links")) |> 
  ggplot(aes(x = year, 
             y = percentage, 
             color = type)) +
  geom_point() +
  geom_line() +
  theme(legend.position = "right", 
        text = element_text(color = "black", 
                            face = "bold",
                            family = "Times"),
        plot.title = element_text(size = 25),
        panel.background = element_rect(fill = "white"), 
        axis.text.y = element_text(size = 15, 
                                   colour = "black"),
        axis.text.x = element_text(size = 15,
                                   colour = "black", 
                                   angle = 45, vjust = 0.5
        ),
        axis.title.x = element_text(size = 20),
        axis.title.y = element_text(size = 20),
        legend.text = element_text(size = "15"), 
        legend.title = element_blank()) +
  labs(title = "Nodes and links through time", 
       y = "Percentage") +
  scale_y_continuous(labels = scales::percent) +
  scale_x_continuous(breaks = seq(2000, 2020, by = 1))

figure_4b

Filtering only the top 10 nodes with best degree in the first 6 clusters.

asn_TM_connected_1 <- 
  author_network |> 
  activate(nodes) |>
  dplyr::mutate(community = as.numeric(community)) |> 
  # filter(community >= 6) |> 
  dplyr::filter(community == 1) |> 
  # group_by(community) |> 
  dplyr::mutate(degree_community = centrality_degree()) |> 
  dplyr::arrange(desc(degree_community)) |> 
  dplyr::slice(1:10)
asn_TM_connected_2 <- 
  author_network |> 
  activate(nodes) |>
  dplyr::mutate(community = as.numeric(community)) |> 
  # filter(community >= 6) |> 
  dplyr::filter(community == 2) |> 
  # group_by(community) |> 
  dplyr::mutate(degree_community = centrality_degree()) |> 
  dplyr::arrange(desc(degree_community))|> 
  dplyr::slice(1:10)
asn_TM_connected_3 <- 
  author_network |> 
  activate(nodes) |>
  dplyr::mutate(community = as.numeric(community)) |> 
  # filter(community >= 6) |> 
  dplyr::filter(community == 3) |> 
  # group_by(community) |> 
  dplyr::mutate(degree_community = centrality_degree()) |> 
  dplyr::arrange(desc(degree_community)) |> 
  dplyr::slice(1:10)
asn_TM_connected_4 <- 
  author_network |> 
  activate(nodes) |>
  dplyr::mutate(community = as.numeric(community)) |> 
  # filter(community >= 6) |> 
  dplyr::filter(community == 4) |> 
  # group_by(community) |> 
  dplyr::mutate(degree_community = centrality_degree()) |> 
  dplyr::arrange(desc(degree_community)) |> 
  dplyr::slice(1:10)
asn_TM_connected_5 <- 
  author_network |> 
  activate(nodes) |>
  dplyr::mutate(community = as.numeric(community)) |> 
  # filter(community >= 6) |> 
  dplyr::filter(community == 5) |> 
  # group_by(community) |> 
  dplyr::mutate(degree_community = centrality_degree()) |> 
  dplyr::arrange(desc(degree_community)) |> 
  dplyr::slice(1:10)
asn_TM_connected_6 <- 
  author_network |> 
  activate(nodes) |>
  dplyr::mutate(community = as.numeric(community)) |> 
  # filter(community >= 6) |> 
  dplyr::filter(community == 6) |> 
  # group_by(community) |> 
  dplyr::mutate(degree_community = centrality_degree()) |> 
  dplyr::arrange(desc(degree_community)) |> 
  dplyr::slice(1:10)

Saving the nodes we’re gonna show

nodes_community_1 <- 
  asn_TM_connected_1 |> 
  activate(nodes) |> 
  as_tibble() |> 
  dplyr::select(name)
nodes_community_2 <- 
  asn_TM_connected_2 |> 
  activate(nodes) |> 
  as_tibble() |> 
  dplyr::select(name)
nodes_community_3 <- 
  asn_TM_connected_3 |> 
  activate(nodes) |> 
  as_tibble() |> 
  dplyr::select(name)
nodes_community_4 <- 
  asn_TM_connected_4 |> 
  activate(nodes) |> 
  as_tibble() |> 
  dplyr::select(name)
nodes_community_5 <- 
  asn_TM_connected_5 |> 
  activate(nodes) |> 
  as_tibble() |> 
  dplyr::select(name)
nodes_community_6 <- 
  asn_TM_connected_6 |> 
  activate(nodes) |> 
  as_tibble() |> 
  dplyr::select(name)
nodes_selected_10 <- 
  nodes_community_1 |> 
  bind_rows(nodes_community_2, 
            nodes_community_3,
            # nodes_community_4,
            # nodes_community_5,
            # nodes_community_6
  )

Filtering selected nodes

asn_selected_nodes <- 
  author_network |> 
  activate(nodes) |> 
  dplyr::filter(name %in% nodes_selected_10$name)  |> 
  dplyr::mutate(degree = centrality_degree())
  
  # dplyr::mutate(final_plot = tidygraph::group_components(type = "weak")) |> 
  # dplyr::filter(final_plot == 1)

Figure 4c Author Network

figure_4c <- 
  asn_selected_nodes |> 
  ggraph(layout = "graphopt") +
  geom_edge_link(width = 1, 
                 colour = "lightgray") +
  geom_node_point(aes(color = community, 
                      size = degree)) +
  geom_node_text(aes(label = name), repel = TRUE) +
  theme_graph()

figure_4c
## Warning: ggrepel: 1 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps

Tree of Science

tos %>% 
    DT::datatable(class = "cell-border stripe", 
                rownames = F, 
                filter = "top", 
                editable = FALSE, 
                extensions = "Buttons", 
                options = list(dom = "Bfrtip",
                               buttons = c("copy",
                                           "csv",
                                           "excel", 
                                           "pdf", 
                                           "print")))