Creating the environment

library(conflicted)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2
library(tidygraph)
library(igraph)
library(ggplot2)
library(bibliometrix)
## Please note that our software is open source and available for use, distributed under the MIT license.
## When it is used in a publication, we ask that authors properly cite the following reference:
## 
## Aria, M. & Cuccurullo, C. (2017) bibliometrix: An R-tool for comprehensive science mapping analysis, 
##                         Journal of Informetrics, 11(4), pp 959-975, Elsevier.
## 
## Failure to properly cite the software is considered a violation of the license.
##                         
## For information and bug reports:
##                         - Take a look at https://www.bibliometrix.org
##                         - Send an email to info@bibliometrix.org   
##                         - Write a post on https://github.com/massimoaria/bibliometrix/issues
##                         
## Help us to keep Bibliometrix and Biblioshiny free to download and use by contributing with a small donation to support our research team (https://bibliometrix.org/donate.html)
## 
##                         
## To start with the Biblioshiny app, please digit:
## biblioshiny()
library(tosr)
library(here)
## here() starts at /home/sebas/Escritorio/datos_diez_i
library(lubridate)
#library(sjrdata)
library(openxlsx)
library(zoo)
library(RSQLite)
library(dplyr)
library(journalabbr)
library(ggraph)
library(plyr)
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
library(XML)
library(readxl)
source("verbs.R")
mi_fuente <- "Times New Roman"
par(family = mi_fuente)
giant.component <- function(graph) {
  cl <- igraph::clusters(graph)
  igraph::induced.subgraph(graph, 
                           which(cl$membership == which.max(cl$csize)))
}
library(httr)   #Url semilla wos y scopus
key <- '17HsyETHSKLxX_AlWgDTH0P0vmFkGnzN4Kh16ZU1-rV0'     
url1 <- paste0('https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=',key,'&exportFormat=xlsx')
httr::GET(url1, write_disk(tf <- tempfile(fileext = ".xlsx")))
year_start = 2002
year_end = 2023

#Declarar carpetas y nombres de archvios csv

figure_2_country_wos_scopus_1 <- readxl::read_excel(tf, 12L)
nombres_deseados <- c("Source","Target","Weigh")
if (!identical(colnames(figure_2_country_wos_scopus_1), nombres_deseados)) {
  colnames(figure_2_country_wos_scopus_1) <- nombres_deseados
}
directorio_actual <- getwd()
ruta_carpeta2 <- file.path(directorio_actual, "figura_dos")
write.csv(figure_2_country_wos_scopus_1, file.path(ruta_carpeta2, "figure_2_country_wos_scopus_1.csv"), row.names = FALSE)
ruta_carpeta3 <- file.path(directorio_actual, "figura_tres")
ruta_carpeta4 <- file.path(directorio_actual, "figura_cuatro")
so_edges <- "SO_edges.csv"
so_nodes <- "SO_nodes.csv"
AU_edges <- "AU_ego_edges.csv"
AU_nodes <- "AU_ego_nodes.csv"

Data getting

wos_scopus <- readxl::read_excel(tf, 1L)
wos <- readxl::read_excel(tf, 2L)
scopus <- readxl::read_excel(tf, 3L)
reference_df <- readxl::read_excel(tf, 4L)
journal_df <- readxl::read_excel(tf, 5L)
author_df <- readxl::read_excel(tf, 6L)
TC_all <- readxl::read_excel(tf, 7L)
figure_1_data <- readxl::read_excel(tf, 8L)
table_2_country <- readxl::read_excel(tf, 10L)
figure_2_country_wos_scopus <- readxl::read_excel(tf, 11L)
figure_2_country_wos_scopus_1 <-
  readxl::read_excel(tf, 12L) |>
  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 <- readxl::read_excel(tf, 13L)
table_4_authors <- readxl::read_excel(tf, 14L)
AU_CO_links <- readxl::read_excel(tf, 15L)
tos <- readxl::read_excel(tf, 16L)
edges_tos <- readxl::read_excel(tf, 17L)
nodes_tos <- readxl::read_excel(tf, 18L)
SO_edges <- readxl::read_excel(tf, 19L)
write.csv(SO_edges, file.path(ruta_carpeta3, so_edges), row.names = FALSE)
SO_nodes <- readxl::read_excel(tf, 20L)
write.csv(SO_nodes, file.path(ruta_carpeta3, so_nodes), row.names = FALSE)
AU_ego_edges <- readxl::read_excel(tf, 21L)
write.csv(AU_ego_edges, file.path(ruta_carpeta4, AU_edges), row.names = FALSE)
AU_ego_nodes <- readxl::read_excel(tf, 22L)
write.csv(AU_ego_nodes,file.path(ruta_carpeta4, AU_nodes), row.names = FALSE)

Summary of WoS and Scopus

table_1 <- 
  tibble(wos = length(wos$AU), # Create a dataframe with the values.
         scopus = length(scopus$AU), 
         total = length(wos_scopus$AU))
table_1 %>% 
  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")))
wos_scopus %>% 
  tidyr::separate_rows(DT, sep = ";") %>% 
  dplyr::count(DT, sort = TRUE)%>% 
  dplyr::mutate(percentage = n /sum(n),
                percentage = percentage * 100,
                percentage = round(percentage, digits = 2)) %>%
  dplyr::rename(total = n) %>% 
  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")))

Resutls

Scientometric Analysis

3.1 Scientific Production

Figure 1a - Scopus + WoS

Combine charts using Python Matplotlib & Reticulate

library(reticulate)
# create a new environment
# conda_create("r-reticulate")
# install Matplotlib
# conda_install("r-reticulate", "matplotlib")
# import Matplotlib (it will be automatically discovered in "r-reticulate")
plt <- import("matplotlib")
np <- import("numpy")
# From Double get integers 
# TC y
TC_all$TC_sum_all <- as.integer(TC_all$TC_sum_all)
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import FuncFormatter
# ax=axes
fig, ax = plt.subplots()
# First plot Total Publications - time series
ax.plot(tpx, tpy, color='r',marker='o', label='Total Publications')
ax.set_xlabel('Year')
ax.set_ylabel('Total Publications', color='r')
# Customization for bar charts
barw = 0.5
ax.bar(sx, sy, color='g', label = 'Scopus', alpha = 0.5, width=barw)
ax.bar(wx1, wy, color='orange', label = 'WoS', alpha=0.8, width=barw)
# Y2 - Total citations
twin_axes = ax.twinx()
twin_axes.plot(tcx, tcy, color = 'purple',marker='o', label='Total Citations')
twin_axes.set_ylabel('Total Citations', color='purple')
# Customize
plt.title('Total Scientific Production vs. Total Citations')
# y2 Total Citation label location
plt.legend(loc='center left')
# True or False to get the grid at the background
ax.grid(False)
# y1 label location
ax.legend(loc='upper left')
# Y2 limit depends of tcy scale in this case 1400 improves label location
plt.ylim(0, 2200) #########  <-----Important--------- """"Change Y2 Coordinate"""""
## (0.0, 2200.0)
# plt.annotate() customize numbers for each position
for i, label in enumerate(tcy):
  plt.annotate(label, (tcx[i], tcy[i] + 0.5), color='purple', size=8)

for i, label in enumerate(tpy):
  ax.annotate(label, (tpx[i], tpy[i] + 0.8), color='red', size=8)

for i, label in enumerate(wy):
  ax.annotate(label, (wx1[i], wy[i] + 0.1), color='brown', size=8)
for i, label in enumerate(sy):
  ax.annotate(label, (sx[i], sy[i] + 0.2),color='green', size=8)
# Rotate x ticks
plt.xticks(tpx)
## ([<matplotlib.axis.XTick object at 0x73ddbcdd13d0>, <matplotlib.axis.XTick object at 0x73ddbcfc6ba0>, <matplotlib.axis.XTick object at 0x73ddbcf5b800>, <matplotlib.axis.XTick object at 0x73ddbce07bf0>, <matplotlib.axis.XTick object at 0x73ddbd602720>, <matplotlib.axis.XTick object at 0x73ddbdb706b0>, <matplotlib.axis.XTick object at 0x73ddbce37980>, <matplotlib.axis.XTick object at 0x73ddbce58320>, <matplotlib.axis.XTick object at 0x73ddbce37b60>, <matplotlib.axis.XTick object at 0x73ddbce58a40>, <matplotlib.axis.XTick object at 0x73ddbce59310>, <matplotlib.axis.XTick object at 0x73ddbce59c10>, <matplotlib.axis.XTick object at 0x73ddbce5a4e0>, <matplotlib.axis.XTick object at 0x73ddbce5ade0>, <matplotlib.axis.XTick object at 0x73ddbce598e0>, <matplotlib.axis.XTick object at 0x73ddbce5b3b0>, <matplotlib.axis.XTick object at 0x73ddbce5bce0>, <matplotlib.axis.XTick object at 0x73ddbce74710>, <matplotlib.axis.XTick object at 0x73ddbce750d0>, <matplotlib.axis.XTick object at 0x73ddbce58e00>, <matplotlib.axis.XTick object at 0x73ddbce75610>, <matplotlib.axis.XTick object at 0x73ddbce76000>], [Text(2023.0, 0, '2023'), Text(2022.0, 0, '2022'), Text(2021.0, 0, '2021'), Text(2020.0, 0, '2020'), Text(2019.0, 0, '2019'), Text(2018.0, 0, '2018'), Text(2017.0, 0, '2017'), Text(2016.0, 0, '2016'), Text(2015.0, 0, '2015'), Text(2014.0, 0, '2014'), Text(2013.0, 0, '2013'), Text(2012.0, 0, '2012'), Text(2011.0, 0, '2011'), Text(2010.0, 0, '2010'), Text(2009.0, 0, '2009'), Text(2008.0, 0, '2008'), Text(2007.0, 0, '2007'), Text(2006.0, 0, '2006'), Text(2005.0, 0, '2005'), Text(2004.0, 0, '2004'), Text(2003.0, 0, '2003'), Text(2002.0, 0, '2002')])
fig.autofmt_xdate(rotation = 70)
# The Y1 ticks depends from tpy scale limits
yticks = [0,2,4,6,8,10,12] ########## <-----Important---- Choose scale .. just specify which numbers you want
ax.set_yticks(yticks)
# Export Figure as SVG
plt.savefig("./figura_uno/figura_1_diez_i.svg")

plt.show()

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 2a - Country Collaboration

figure_2a <- 
  figure_2_country_wos_scopus_1 |>
  activate(edges) |> 
  # tidygraph::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_2a

#ggsave("./figura_dos/figura_2a_dies.svg", plot = figure_2a, device = "svg")

Figure 2b Clusters

figure_2b <- 
  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"),
        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_2b

#ggsave("./figura_dos/figura_2b_dies.svg",  plot = figure_2b,device = "svg")

Figure 2c Longitudinal

# 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 >= year_start,
                year <= year_end) |> 
  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 >= year_start,
                year <= year_end) |> 
  dplyr::ungroup() |> 
  dplyr::mutate(percentage = n / max(n)) |> 
  select(year, percentage)
figure_2c <- 
  figure_2c_nodes |> 
  dplyr::mutate(type = "nodes",
         year = as.numeric(year)) |> 
  bind_rows(figure_2c_edges |> 
              dplyr::mutate(type = "links",
                     year = as.numeric(year))) |> 
  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(year_start, year_end, by = 1))

figure_2c

#ggsave("./figura_dos/figura_2c_dies.svg", plot = figure_2c,device = "svg")

3.3 Journal Analysis

Table 3 Most productive journals

table_3_journal |> 
  dplyr::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)

Selecting nodes to show

figure_3a_1 <- 
  SO_edges %>% 
  tidygraph::as_tbl_graph() %>% 
  tidygraph::activate(nodes) %>%
  tidygraph::mutate(id = SO_nodes$id) %>% 
  #tidygraph::mutate(id = name) 
  tidygraph::left_join(SO_nodes) %>% 
  tidygraph::select(-id) %>% 
  tidygraph::rename(name = Label) %>% 
  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_1

#ggsave("./figura_tres/figura_3a_1_dies.svg", plot = figure_3a_1, device = "svg")

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

#ggsave("./figura_tres/figura_3b_dies.svg",  plot = figure_3b,  device = "svg")

Figure 3c Longitudinal

# Create a dataframe with links 
figure_3c_edges <- 
  journal_df |>
  select(from = JI_main, to = JI_ref, PY = PY_ref) %>% 
  dplyr::filter(from != to) |> 
  tidygraph::as_tbl_graph() |> 
  activate(edges) |> 
  as_tibble() |> 
  dplyr::select(year = PY) |> 
  dplyr::count(year) |> 
  dplyr::filter(year >= year_start,
                year <= year_end) |> 
  dplyr::mutate(percentage = n/max(n)) |> 
  dplyr::select(year, percentage)
# Create a data frame with author and year 
figure_3c_nodes <- # 21 row 
  journal_df |>
  select(from = JI_main, to = JI_ref, PY = PY_ref) %>% 
  dplyr::filter(from != to) |> 
  tidygraph::as_tbl_graph() |> 
  activate(edges) |> 
  as_tibble() |> 
  dplyr::select(CO = from, 
                year = PY) |>
  bind_rows(journal_df |>
              select(from = JI_main, 
                     to = JI_ref, 
                     PY = PY_ref) %>%  
              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 >= year_start,
                year <= year_end) |> 
  dplyr::ungroup() |> 
  dplyr::mutate(percentage = n / max(n)) |> 
  select(year, percentage)

plotting figure 3b

figure_3c <- 
  figure_3c_nodes |> 
  dplyr::mutate(type = "nodes") |> 
  bind_rows(figure_3c_edges |> 
              dplyr::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 = 60, 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(year_start, year_end, by = 1))

figure_3c

#ggsave("./figura_tres/figura_3c_DIES.svg", plot = figure_3c, device = "svg")

3.4 Author Analysis

Table 4

table_4_authors |> 
  dplyr::select(authors_total, papers_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")))

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

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

ggsave("./figura_cuatro/figura_4a_dies.svg", 
       plot = figure_4a, 
       device = "svg")

Figure 4b Longitudinal

# 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 >= year_start,
                year <= year_end) |> 
  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 >= year_start,
                year <= year_end) |> 
  dplyr::ungroup() |> 
  dplyr::mutate(percentage = n / max(n)) |> 
  select(year, percentage)

plotting figure 4b

figure_4b <- 
  fig_1c_nodes |> 
  dplyr::mutate(type = "nodes") |> 
  bind_rows(fig_1c_edges |> 
              dplyr::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(year_start, year_end, by = 1))

figure_4b

ggsave("./figura_cuatro/figura_4b_dies.svg", 
       plot = figure_4b, 
       device = "svg")

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

ggsave("./figura_cuatro/figura_4c_dies.svg", 
       plot = figure_4c, 
       device = "svg")

3.4.1 Ego top 10 authors

merging ego_networks

egos  <- 
  AU_ego_edges %>%
  tidygraph::as_tbl_graph() %>% 
  tidygraph::activate(nodes) %>%
  tidygraph::mutate(id = AU_ego_nodes$id) %>%
  dplyr::left_join(AU_ego_nodes %>% 
                     tidygraph::mutate(id = as.character(id))) %>% 
  dplyr::mutate(component = as.character(component))


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

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")))