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.1 ✔ 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 C:/Users/Sema/Documents/Rpubs/ariza
library(lubridate)
#library(sjrdata)
library(openxlsx)
library(zoo)
library(RSQLite)
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(dplyr)
library(journalabbr)
library(ggraph)
library(XML)
library(readxl)
library(svglite)
source("verbs.R")
giant.component <- function(graph) {
cl <- igraph::clusters(graph)
igraph::induced.subgraph(graph,
which(cl$membership == which.max(cl$csize)))
}
## La carpeta ya existe: figura_tres
## La carpeta ya existe: figura_cuatro
## La carpeta ya existe: figura_dos
## La carpeta ya existe: figura_una
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")))
Combine charts using Python Matplotlib & Reticulate
library(reticulate)
numpy <- import("numpy")
matplotlib <- import("matplotlib")
# Definir año de inicio y fin
year_start <- 2003
year_end <- 2024
years_full <- seq(year_start, year_end)
# Eliminar datos previos al año de inicio en figure_1_data
figure_1_data <- figure_1_data %>% dplyr::filter(PY >= year_start)
# Crear datos faltantes y añadir filas a figure_1_data
years_missing <- setdiff(years_full, figure_1_data$PY)
for (year in years_missing) {
total_wos <- wos %>% dplyr::filter(PY == year) %>% nrow()
total_scopus <- scopus %>% dplyr::filter(PY == year) %>% nrow()
total_wos_scopus <- wos_scopus %>% dplyr::filter(PY == year) %>% nrow()
new_row <- data.frame(PY = year, total = total_wos_scopus, scopus = total_scopus, wos = total_wos)
figure_1_data <- dplyr::bind_rows(figure_1_data, new_row)
}
# Ordenar los datos por año de forma descendente
figure_1_data <- figure_1_data %>% dplyr::arrange(desc(PY))
# Crear TC_all y eliminar datos previos al año de inicio
TC_all <- data.frame(PY = integer(), TC_sum_all = numeric(), TC_percentage = numeric())
for (year in years_full) {
ncitas_wos <- wos %>% dplyr::filter(PY == year) %>% dplyr::summarize(sum(TC, na.rm = TRUE)) %>% dplyr::pull()
ncitas_scopus <- scopus %>% dplyr::filter(PY == year) %>% dplyr::summarize(sum(TC, na.rm = TRUE)) %>% dplyr::pull()
ncitas <- ncitas_wos + ncitas_scopus
new_row_tc <- data.frame(PY = year, TC_sum_all = ncitas, TC_percentage = NA)
TC_all <- dplyr::bind_rows(TC_all, new_row_tc)
}
# Calcular porcentaje de citas
total_citas <- sum(TC_all$TC_sum_all, na.rm = TRUE)
TC_all <- TC_all %>%
dplyr::mutate(TC_percentage = round(TC_sum_all / total_citas * 100, 2)) %>%
dplyr::arrange(desc(PY))
# Convertir TC_sum_all a entero
TC_all$TC_sum_all <- as.integer(TC_all$TC_sum_all)
import matplotlib.pyplot as plt
# from matplotlib.ticker import FuncFormatter
def clean_integer_formatter(x, pos):
return '{:d}'.format(int(x))
fig, ax = plt.subplots(figsize=(11, 7.5))
ax.plot(tpx, tpy, color='r', marker='o', label='Total Publications')
ax.set_xlabel('Year', fontsize=14)
ax.set_ylabel('Total Publications', color='r', fontsize=14)
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)
twin_axes = ax.twinx()
twin_axes.plot(tcx, tcy, color='purple', marker='o', label='Total Citations')
twin_axes.set_ylabel('Total Citations', color='purple', fontsize=14)
plt.title('Total Scientific Production vs. Total Citations', fontsize=16)
plt.legend(loc='center left', fontsize=12)
ax.grid(False)
ax.legend(loc='upper left', fontsize=12)
twin_axes.set_ylim(0, max(tcy)+100)
## (0.0, 705.0)
for i, label in enumerate(tcy):
twin_axes.annotate(label, (tcx[i], tcy[i] + 0.5), color='purple', size=12)
for i, label in enumerate(tpy):
ax.annotate(label, (tpx[i], tpy[i] + 0.8), color='red', size=12)
for i, label in enumerate(wy):
ax.annotate(label, (wx1[i], wy[i] + 0.1), color='brown', size=12)
for i, label in enumerate(sy):
ax.annotate(label, (sx[i], sy[i] + 0.2), color='green', size=12)
ax.set_xticks(tpx)
ax.set_xticklabels([int(year) for year in tpx], fontsize=12, rotation=75)
# ax.yaxis.set_major_formatter(FuncFormatter(clean_integer_formatter))
# twin_axes.yaxis.set_major_formatter(FuncFormatter(clean_integer_formatter))
ax.tick_params(axis='y', labelsize=12)
twin_axes.tick_params(axis='y', labelsize=12)
plt.savefig("./figura_una/figura_1.svg")
plt.show()
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 <-
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.svg",
plot = figure_2a,
device = "svg")
library(svglite)
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.svg",
plot = figure_2b,
device = "svg")
# 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.svg",
plot = figure_2c,
device = "svg")
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")))
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::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 = as.factor(community), size = degree)) +
geom_node_text(aes(label = name), repel = TRUE) +
scale_size(name = "Degree") +
scale_color_discrete(name = "Communities") + # Cambié scale_color_binned a scale_color_discrete
theme_graph()
figure_3a_1
ggsave("./figura_tres/figura_3a_1.svg",
plot = figure_3a_1,
device = "svg")
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.svg",
plot = figure_3b,
device = "svg")
# 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.svg",
plot = figure_3c,
device = "svg")
{r} # # Crear y asignar la figura a un objeto # 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") + # theme_graph() # # #
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")))