From 3c85acdd04ce4d48e0923cbd4b50ffcc14e94cd3 Mon Sep 17 00:00:00 2001 From: massimoaria Date: Thu, 2 May 2019 14:09:19 +0200 Subject: [PATCH] Minor fixes --- R/biblioNetwork.R | 228 ++++++++++++++++++++------------------ R/cocMatrix.R | 2 + R/networkPlot.R | 2 + inst/biblioshiny/server.R | 10 +- inst/biblioshiny/ui.R | 4 +- 5 files changed, 130 insertions(+), 116 deletions(-) diff --git a/R/biblioNetwork.R b/R/biblioNetwork.R index 78f3eddd..6f0e6792 100644 --- a/R/biblioNetwork.R +++ b/R/biblioNetwork.R @@ -64,119 +64,127 @@ #' #' @export -biblioNetwork <- function(M, analysis = "coupling", network = "authors", sep = ";", shortlabel=TRUE){ - - crossprod <- Matrix::crossprod - NetMatrix=NA - if (analysis=="coupling"){ - switch(network, - authors={ - WA=cocMatrix(M, Field="AU", type = "sparse", sep) - WCR=cocMatrix(M, Field="CR", type = "sparse", sep) - CRA = crossprod(WCR, WA) - NetMatrix = crossprod(CRA, CRA) - }, - references={ - WCR=Matrix::t(cocMatrix(M, Field="CR", type = "sparse", sep)) - NetMatrix = crossprod(WCR, WCR) - }, - sources={ - WSO=cocMatrix(M, Field="SO", type = "sparse", sep) - WCR=cocMatrix(M, Field="CR", type = "sparse", sep) - CRSO = crossprod(WCR, WSO) - NetMatrix = crossprod(CRSO, CRSO) - }, - countries={ - WCO=cocMatrix(M, Field="AU_CO", type = "sparse", sep) - WCR=cocMatrix(M, Field="CR", type = "sparse", sep) - CRCO = crossprod(WCR, WCO) - NetMatrix = crossprod(CRCO, CRCO) +biblioNetwork <- + function(M, + analysis = "coupling", + network = "authors", + sep = ";", + shortlabel = TRUE) { + crossprod <- Matrix::crossprod + NetMatrix = NA + + if (analysis == "coupling") { + switch( + network, + authors = { + WA = cocMatrix(M, Field = "AU", type = "sparse", sep) + WCR = cocMatrix(M, Field = "CR", type = "sparse", sep) + CRA = crossprod(WCR, WA) + NetMatrix = crossprod(CRA, CRA) + }, + references = { + WCR = Matrix::t(cocMatrix(M, Field = "CR", type = "sparse", sep)) + NetMatrix = crossprod(WCR, WCR) + }, + sources = { + WSO = cocMatrix(M, Field = "SO", type = "sparse", sep) + WCR = cocMatrix(M, Field = "CR", type = "sparse", sep) + CRSO = crossprod(WCR, WSO) + NetMatrix = crossprod(CRSO, CRSO) + }, + countries = { + WCO = cocMatrix(M, Field = "AU_CO", type = "sparse", sep) + WCR = cocMatrix(M, Field = "CR", type = "sparse", sep) + CRCO = crossprod(WCR, WCO) + NetMatrix = crossprod(CRCO, CRCO) + } + ) } - )} - - if (analysis=="co-occurrences"){ - switch(network, - authors={ - WA=cocMatrix(M, Field="AU", type = "sparse", sep) - NetMatrix = crossprod(WA, WA) - }, - keywords={ - WK=cocMatrix(M, Field="ID", type = "sparse", sep) - NetMatrix = crossprod(WK,WK) - }, - author_keywords={ - WK=cocMatrix(M, Field="DE", type = "sparse", sep) - NetMatrix = crossprod(WK,WK) - }, - titles={ - WK=cocMatrix(M, Field="TI_TM", type = "sparse", sep) - NetMatrix = crossprod(WK,WK) - }, - abstracts={ - WK=cocMatrix(M, Field="AB_TM", type = "sparse", sep) - NetMatrix = crossprod(WK,WK) - }, - sources={ - WSO=cocMatrix(M, Field="SO", type = "sparse", sep) - NetMatrix = crossprod(WSO, WSO) - } - )} - - if (analysis=="co-citation"){ - switch(network, - authors={ - WA=cocMatrix(M, Field="CR_AU", type = "sparse", sep) - NetMatrix = crossprod(WA, WA) - }, - references={ - WCR=cocMatrix(M, Field="CR", type = "sparse", sep) - NetMatrix = crossprod(WCR, WCR) - ### reduce name length - # A=row.names(NetMatrix) - # ind=unlist(regexec("*V[0-9]", A)) - # A[ind>-1]=substr(A[ind>-1],1,(ind[ind>-1]-1)) - # ind=unlist(regexec("*DOI ", A)) - # A[ind>-1]=substr(A[ind>-1],1,(ind[ind>-1]-1)) - # row.names(NetMatrix)=A - # colnames(NetMatrix)=A - ### - }, - sources={ - WSO=cocMatrix(M, Field="CR_SO", type = "sparse", sep) - NetMatrix = crossprod(WSO, WSO) - } - )} - if (analysis=="collaboration"){ - switch(network, - authors={ - WA=cocMatrix(M, Field="AU", type = "sparse", sep) - NetMatrix = crossprod(WA, WA) - }, - universities={ - WUN=cocMatrix(M, Field="AU_UN", type = "sparse", sep) - NetMatrix = crossprod(WUN, WUN) - }, - countries={ - WCO=cocMatrix(M, Field="AU_CO", type = "sparse", sep) - NetMatrix = crossprod(WCO, WCO) - }) - } - # delete empty vertices - NetMatrix=NetMatrix[nchar(colnames(NetMatrix))!=0,nchar(colnames(NetMatrix))!=0] - - # short label for scopus references - if (network=="references"){ - ind=which(regexpr("[A-Za-z]",substr(colnames(NetMatrix),1,1))==1) - NetMatrix=NetMatrix[ind,ind] - if (isTRUE(shortlabel)){ - LABEL<-labelShort(NetMatrix,db=tolower(M$DB[1])) - LABEL<-removeDuplicatedlabels(LABEL) - colnames(NetMatrix)=rownames(NetMatrix)=LABEL} + if (analysis == "co-occurrences") { + switch( + network, + authors = { + WA = cocMatrix(M, Field = "AU", type = "sparse", sep) + }, + keywords = { + WA = cocMatrix(M, Field = "ID", type = "sparse", sep) + }, + author_keywords = { + WA = cocMatrix(M, Field = "DE", type = "sparse", sep) + }, + titles = { + WA = cocMatrix(M, Field = "TI_TM", type = "sparse", sep) + }, + abstracts = { + WA = cocMatrix(M, Field = "AB_TM", type = "sparse", sep) + }, + sources = { + WA = cocMatrix(M, Field = "SO", type = "sparse", sep) + } + ) + NetMatrix = crossprod(WA, WA) + + } + + + + if (analysis == "co-citation") { + switch( + network, + authors = { + WA = cocMatrix(M, Field = "CR_AU", type = "sparse", sep) + }, + references = { + WA = cocMatrix(M, Field = "CR", type = "sparse", sep) + }, + sources = { + WA = cocMatrix(M, Field = "CR_SO", type = "sparse", sep) + } + ) + NetMatrix = crossprod(WA, WA) + + } + + if (analysis == "collaboration") { + switch( + network, + authors = { + WA = cocMatrix(M, Field = "AU", type = "sparse", sep) + + }, + universities = { + WA = cocMatrix(M, Field = "AU_UN", type = "sparse", sep) + + }, + countries = { + WA = cocMatrix(M, Field = "AU_CO", type = "sparse", sep) + } + ) + NetMatrix = crossprod(WA, WA) + + } + + + # delete empty vertices + NetMatrix = NetMatrix[nchar(colnames(NetMatrix)) != 0, nchar(colnames(NetMatrix)) != 0] + + # short label for scopus references + if (network == "references") { + ind = which(regexpr("[A-Za-z]", substr(colnames(NetMatrix), 1, 1)) == 1) + NetMatrix = NetMatrix[ind, ind] + if (isTRUE(shortlabel)) { + LABEL <- labelShort(NetMatrix, db = tolower(M$DB[1])) + LABEL <- removeDuplicatedlabels(LABEL) + colnames(NetMatrix) = rownames(NetMatrix) = LABEL + } + + } + # if (analysis != "coupling") { + # attr(NetMatrix, "PY") <- attr(WA, "PY") + # } + return(NetMatrix) } - - return(NetMatrix) -} ### shortlabel labelShort <- function(NET,db="isi"){ diff --git a/R/cocMatrix.R b/R/cocMatrix.R index 898d4bbb..6edef62f 100644 --- a/R/cocMatrix.R +++ b/R/cocMatrix.R @@ -144,6 +144,7 @@ if (type=="sparse" & !isTRUE(binary)){ } WF=WF[,!is.na(uniqueField)] + #WF=attrPY(M,WF) # Median Year of each attribute return(WF) } @@ -156,3 +157,4 @@ reduceRefs<- function(A){ A[ind>-1]=substr(A[ind>-1],1,(ind[ind>-1]-1)) return(A) } + diff --git a/R/networkPlot.R b/R/networkPlot.R index 8700f276..b6ac4ba1 100644 --- a/R/networkPlot.R +++ b/R/networkPlot.R @@ -287,6 +287,8 @@ clusteringNetwork <- function(bsk.network,cluster){ }else{C='gray70'} return(C) }) + E(bsk.network)$lty=1 + E(bsk.network)$lty[E(bsk.network)$color=="gray70"]=5 ### end cl=list() diff --git a/inst/biblioshiny/server.R b/inst/biblioshiny/server.R index 1858dddc..a6af0011 100644 --- a/inst/biblioshiny/server.R +++ b/inst/biblioshiny/server.R @@ -2194,7 +2194,7 @@ server <- function(input, output, session) { #par(bg="grey92", mar=c(0,0,0,0)) values$cocnet=networkPlot(values$NetWords, normalize=normalize,n = n, Title = values$Title, type = input$layout, - size.cex=TRUE, size=5 , remove.multiple=F, edgesize = input$edgesize, labelsize=input$labelsize,label.cex=label.cex, + size.cex=TRUE, size=5 , remove.multiple=F, edgesize = input$edgesize*3, labelsize=input$labelsize,label.cex=label.cex, label.n=label.n,edges.min=input$edges.min,label.color = F, curved=curved,alpha=input$cocAlpha, cluster=input$cocCluster) }else{ @@ -2238,7 +2238,7 @@ server <- function(input, output, session) { if (input$cocit.curved=="Yes"){curved=TRUE}else{curved=FALSE} values$cocitnet=networkPlot(values$NetRefs, normalize=NULL, n = n, Title = values$Title, type = input$citlayout, - size.cex=TRUE, size=5 , remove.multiple=F, edgesize = input$citedgesize, + size.cex=TRUE, size=5 , remove.multiple=F, edgesize = input$citedgesize*3, labelsize=input$citlabelsize,label.cex=label.cex, curved=curved, label.n=label.n,edges.min=input$citedges.min,label.color = F,remove.isolates = FALSE, alpha=input$cocitAlpha, cluster=input$cocitCluster) @@ -2285,7 +2285,7 @@ server <- function(input, output, session) { if (input$collayout=="worldmap"){type="auto"} values$colnet=networkPlot(values$ColNetRefs, normalize=normalize, n = n, Title = values$Title, type = type, - size.cex=TRUE, size=5 , remove.multiple=F, edgesize = input$coledgesize, + size.cex=TRUE, size=5 , remove.multiple=F, edgesize = input$coledgesize*3, labelsize=input$collabelsize,label.cex=label.cex, curved=curved, label.n=label.n,edges.min=input$coledges.min,label.color = F,alpha=input$colAlpha, remove.isolates = T, cluster=input$colCluster) @@ -2391,7 +2391,9 @@ server <- function(input, output, session) { vn$nodes$label=LABEL vn$edges$num=1 - + vn$edges$dashes=FALSE + vn$edges$dashes[vn$edges$lty==2]=TRUE + ## opacity vn$nodes$color=adjustcolor(vn$nodes$color,alpha=min(c(opacity+0.2,1))) vn$edges$color=adjustcolor(vn$edges$color,alpha=opacity) diff --git a/inst/biblioshiny/ui.R b/inst/biblioshiny/ui.R index e4d988df..7b26f448 100644 --- a/inst/biblioshiny/ui.R +++ b/inst/biblioshiny/ui.R @@ -300,10 +300,10 @@ navbarMenu("Sources", ) ), #### MOST RELEVANT CITED SOURCES ---- - tabPanel("Most Cited Sources", + tabPanel("Most Local Cited Sources", sidebarLayout( sidebarPanel(width=3, - h3(em(strong("Most Cited Sources (from Reference Lists)"))), + h3(em(strong("Most Local Cited Sources (from Reference Lists)"))), br(), h4(em(strong("Graphical Parameters: "))), " ",