Skip to content

Commit

Permalink
Merge pull request #302 from massimoaria/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
massimoaria authored Feb 9, 2023
2 parents ffe3426 + f4b7d38 commit cbac1f2
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 210 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ importFrom(dplyr,relocate)
importFrom(dplyr,rename)
importFrom(dplyr,rename_with)
importFrom(dplyr,right_join)
importFrom(dplyr,row_number)
importFrom(dplyr,rowwise)
importFrom(dplyr,select)
importFrom(dplyr,slice)
Expand Down Expand Up @@ -233,6 +234,7 @@ importFrom(igraph,E)
importFrom(igraph,V)
importFrom(igraph,arpack_defaults)
importFrom(igraph,as_adjacency_matrix)
importFrom(igraph,as_long_data_frame)
importFrom(igraph,authority_score)
importFrom(igraph,betweenness)
importFrom(igraph,centr_betw)
Expand Down
21 changes: 11 additions & 10 deletions R/cocMatrix.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#' Occurrence Matrix
#' Bibliographic bipartite network matrices
#'
#' \code{cocMatrix} computes occurences between elements of a Tag Field from a bibliographic data frame. Manuscript is the unit of analysis.
#' \code{cocMatrix} computes occurrences between elements of a Tag Field from a bibliographic data frame. Manuscript is the unit of analysis.
#'
#' This occurrence matrix can be transformed into a collection of compatible
#' networks. Through matrix multiplication you can obtain different networks.
#' This occurrence matrix represents a bipartite network which can be transformed into a collection of bibliographic
#' networks such as coupling, co-citation, etc..
#'
#' The function follows the approach proposed by Batagelj & Cerinsek (2013) and Aria & cuccurullo (2017).\cr\cr
#'
#' References:\cr
Expand Down Expand Up @@ -36,22 +37,22 @@
#' @param short is a logical. If TRUE all items with frequency<2 are deleted to reduce the matrix size.
#' @param remove.terms is a character vector. It contains a list of additional terms to delete from the documents before term extraction. The default is \code{remove.terms = NULL}.
#' @param synonyms is a character vector. Each element contains a list of synonyms, separated by ";", that will be merged into a single term (the first word contained in the vector element). The default is \code{synonyms = NULL}.
#' @return a co-occurrence matrix with cases corresponding to manuscripts and variables to the
#' @return a bipartite network matrix with cases corresponding to manuscripts and variables to the
#' objects extracted from the Tag \code{Field}.
#'
#' @examples
#' # EXAMPLE 1: Articles x Authors co-occurrence matrix
#' # EXAMPLE 1: Articles x Authors occurrence matrix
#'
#' data(scientometrics, package = "bibliometrixData")
#' WA <- cocMatrix(scientometrics, Field = "AU", type = "sparse", sep = ";")
#'
#' # EXAMPLE 2: Articles x Cited References co-occurrence matrix
#' # EXAMPLE 2: Articles x Cited References occurrence matrix
#'
#' # data(scientometrics, package = "bibliometrixData")
#'
#' # WCR <- cocMatrix(scientometrics, Field = "CR", type = "sparse", sep = ";")
#'
#' # EXAMPLE 3: Articles x Cited First Authors co-occurrence matrix
#' # EXAMPLE 3: Articles x Cited First Authors occurrence matrix
#'
#' # data(scientometrics, package = "bibliometrixData")
#' # scientometrics <- metaTagExtraction(scientometrics, Field = "CR_AU", sep = ";")
Expand All @@ -68,10 +69,10 @@ cocMatrix<-function(M, Field = "AU", type = "sparse", n=NULL, sep = ";",binary=T
#
# The function creates occurrences data between Works and Field
#
# type indicates the output format of co-occurrences:
# type indicates the output format of occurrences:
# "matrix" argument generates a W x Field sparse matrix
# "sparse" argument generates a compact representation of the matrix (using the package Matrix)
# it represents a compact representation of a co-occurrences matrix.
# it represents a compact representation of a occurrences matrix.
# Field indicates the ISI Tag
# if Field is AU -> WA (Works x Authors)
# if Field is CR -> WR (Works x References)
Expand Down
9 changes: 6 additions & 3 deletions R/collabByRegionPlot.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' A function to plot country collaboration networks by Region
#' The function \code{\link{networkPlot}} can plot a bibliographic network previously created by \code{\link{biblioNetwork}}.
#' Country Collaboration Networks by Region
#'
#' A function to create and plot country collaboration networks by Region
#'
#' @param NetMatrix is a country collaboration matrix obtained by the function \code{\link{biblioNetwork}}.
#' @param normalize is a character. It can be "association", "jaccard", "inclusion","salton" or "equivalence" to obtain Association Strength, Jaccard,
Expand Down Expand Up @@ -55,7 +56,9 @@
#'
#' NetMatrix <- biblioNetwork(management, analysis = "collaboration", network = "countries")
#'
#' net <- collabByRegionPlot(NetMatrix, edgesize = 4, label.cex = TRUE, labelsize=2.5, weighted = TRUE, size=0.5, size.cex=TRUE, community.repulsion = 0, verbose=FALSE)
#' net <- collabByRegionPlot(NetMatrix, edgesize = 4, label.cex = TRUE, labelsize=2.5,
#' weighted = TRUE, size=0.5, size.cex=TRUE, community.repulsion = 0,
#' verbose=FALSE)
#'
#' cbind(names(net))
#'
Expand Down
47 changes: 43 additions & 4 deletions R/histPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,53 @@ histPlot<-function(histResults, n=20, size = 5, labelsize = 5, title_as_label =
layout_m$y <- (diff(range(layout_m$x))/diff(range(layout_m$y)))*layout_m$y

################
df_net <- dataFromIgraph(bsk.network, layout=as.matrix(layout_m[c("x","y")]), niter=50000, arrow.gap=0)
# df_net <- dataFromIgraph(bsk.network, layout=as.matrix(layout_m[c("x","y")]), niter=50000, arrow.gap=0)
# df_net$color <- "slategray1"
# df_net <- left_join(df_net,layout_m[c("name","color")], by = "name") %>%
# rename(
# color = .data$color.x,
# color_v =.data$color.y
# )
# #names(df_net)[10:11] <- c("color", "color_v")

df_net <- igraph::as_long_data_frame(bsk.network)
df_net$color <- "slategray1"
df_net <- left_join(df_net,layout_m[c("name","color")], by = "name") %>%

ID <- setdiff(df_net$to,df_net$from)

df_from <- df_net %>%
select(.data$from,.data$to,.data$color,.data$from_name, .data$from_title, .data$from_keywords, .data$from_keywordsplus, .data$from_id, .data$from_size, .data$from_years)

df_to <- df_net %>% dplyr::filter(.data$to %in% ID) %>%
mutate(from2=.data$to) %>%
select(.data$from2,.data$to,.data$color,.data$to_name, .data$to_title, .data$to_keywords, .data$to_keywordsplus, .data$to_id, .data$to_size, .data$to_years)

df_to <- df_to[!duplicated(df_to$to),]

label <- c("from", "to", "color","name", "title", "keywords", "keywordsplus", "id", "size", "years")

names(df_from) <- label
names(df_to) <- label

df_net <- rbind(df_from,df_to)

layout_norm <- layout_m %>%
mutate(x = (.data$x-min(.data$x))/(max(.data$x)-min(.data$x)),
y = (.data$y-min(.data$y))/(max(.data$y)-min(.data$y)))
df_net <- left_join(df_net,layout_norm[c("name","color","x","y")], by = c("name" ="name")) %>%
rename(
color = .data$color.x,
color_v =.data$color.y
)
#names(df_net)[10:11] <- c("color", "color_v")
)

df_coord <- layout_norm %>%
mutate(to=row_number()) %>%
select(.data$to,.data$x,.data$y) %>%
rename(xend=.data$x,
yend=.data$y)

df_net <- df_net %>%
left_join(df_coord, by="to")

ylength <- diff(range(df_net$years))+1
Ylabel <- (as.character(seq(min(df_net$years),max(df_net$years),length.out=ylength)))
Expand Down
Loading

0 comments on commit cbac1f2

Please sign in to comment.