2017-10-29 3 views
-4

공동 저자의 PubMed 발행물 (226 레코드)의 이분 그래프를 작성한 첫 번째 시도. 그래프R 데이터를 .GEXF 형식으로 변환

11810598;Chêne G, Angelini E, Cotte L, Lang JM, Morlat P, Rancinan C, May T, Journot V, Raffi F, Jarrousse B, Grappin M, Lepeu G, Molina JM;2002;Mar;Role of long-term nucleoside-analogue therapy in lipodystrophy and metabolic disorders in human immunodeficiency virus-infected patients. 

 

> InputFile = 'JMMolina_PubMed.csv' 

    # Read the CSV input file into the initial JMMpubs data frame 

> setwd('~/Dropbox/R') 
> JMMpubs <- read.csv(file=InputFile , header = 
> FALSE , sep = ";" , strip.white = TRUE) 

> names(JMMpubs) <- c("ID","AuthList", "Year", "Month", "Title") 

    # build a new data frame IdAuth with one Id line for each coauthor 
    # therefor the first article which has 13 co-authors will generate 13 lines with the same Id 

> Authors <- strsplit(as.character(JMMpubs$AuthList), split = ", ") 

> IdAuth <- data.frame(Id = rep(JMMpubs$ID, sapply(Authors,length)), Author = unlist(Authors)) 

    # Now I would like to export this data to Gephi 

    # The nodes of the graph should be the UNIQUE names in Authors 

> UniqueAuthors <- unique(unlist(Authors)) 

가장자리 IdAuth 각 행되어야 다음은 입력 파일 (CSV 한 선)의 예이다. 나는 각 edge에 발행물 JMMpubs$Year의 연대를 관련시키고 싶다. (최근의 edge는 적색으로, 오래된 것은 더 옅은 색상으로 칠한다.)

답변

0

비슷한 문제가 있습니다. 내 솔루션은 다음과 같습니다.

작동하려면 데이터를 약간 개편해야 할 필요가 있습니다. 올바르게 이해했다면 ID에 연결된 작성자가 필요합니다. 원래의 대답은 user1317221_G

에 의해이 게시물 https://stackoverflow.com/a/16177624/8080865

나는대로 DF를 설정합니다 :이 당신이 당신의 답을 알아낼 도움이되기를 바랍니다

df3<-data.frame(Author = c("fawf", "ewew", "wewe", "wrewe", "zare") 
        ID= "11", "11", "11"... etc)´ 

###TNET solution WoRKS 
#create an identifier df for each author 
dfnames <- data.frame(i = as.numeric(df3$Id), 
         value = df$author) 

library(tnet) 
tdf  <- as.tnet(cbind(df3[,1],df3[,2]), type="binary two-mode tnet") 
relations <- projecting_tm(tdf, method = "sum") 


# match original names 
relations[["i"]] <- dfnames[match(relations[['i']], dfnames[['']]) , 'value'] 
relations[["j"]] <- dfnames[match(relations[['j']], dfnames[['i']]) , 'value'] 

# clean up names 
names(relations) <- c("source" , "target", "weight") 

?

관련 문제