Wikipedia Marvel cinematic universe phases network

net

The construction of the network is described in the article How to make interactive networks using R programming with an interactive visualization based on visNetwork.

From the visualization code, I extracted the network description to the file marvel.json.

> wdir <- "C:/Users/vlado/DL/data/marvel/"
> setwd(wdir)
> library(jsonlite)
> M <- fromJSON("marvel.json")
> str(M)
List of 3
 $ x      :List of 19
  ..$ nodes           :List of 3
  .. ..$ id   : chr [1:82] "Bruce Banner Hulk" "Clint Barton Hawkeye" "Phil Coulson" "Nick Fury" ...
  .. ..$ group: chr [1:82] "Character" "Character" "Character" "Character" ...
  .. ..$ label: chr [1:82] "Bruce Banner Hulk" "Clint Barton Hawkeye" "Phil Coulson" "Nick Fury" ...
  ..$ edges           :List of 2
  .. ..$ from: chr [1:202] "Bruce Banner Hulk" "Bruce Banner Hulk" "Clint Barton Hawkeye" "Phil Coulson" ...
  .. ..$ to  : chr [1:202] "The Incredible Hulk" "Marvel's The Avengers" "Marvel's The Avengers" "Iron Man 1" ...
  ..$ nodesToDataframe: logi TRUE
  ..$ edgesToDataframe: logi TRUE
  ..$ options         :List of 7
  .. ..$ width       : chr "100%"
  .. ..$ height      : chr "100%"
...
  ..$ main            :List of 2
  .. ..$ text : chr "The Marvel Cinematic Universe Network"
...
 $ evals  : list()
 $ jsHooks: list()

I transformed the data into Pajek format.

> names <- M$x$nodes$id
> B <- factor(M$x$nodes$group); mod <- levels(B)
> F <- factor(M$x$edges$from,levels=names,ordered=TRUE)
> T <- factor(M$x$edges$to,levels=names,ordered=TRUE)
> n <- length(names)
> net <- file("marvel.net","w"); 
> cat('%',M$x$main$text,'\n*vertices ',n,'\n',file=net)
> clu <- file("marvelMode.clu","w"); cat('%',file=clu) 
> for(i in 1:length(mod)) cat(' ',i,mod[i],file=clu)
> cat('\n*vertices ',n,'\n',file=clu)
> for(v in 1:n) {
+   cat(v,' "',names[v],'"\n',sep='',file=net)
+   cat(B[v],'\n',file=clu)
+ }
> cat('*arcs\n',file=net)
> for(a in 1:length(F)) cat(F[a],' ',T[a],' 1\n',sep='',file=net)
> close(net); close(clu)
> table(B)
B
Character     Movie 
       59        23 

I manually added 59 to the *vertices in marvel.net.

NetsJSON

> wdir <- "C:/Users/vlado/DL/data/multi"
> setwd(wdir)
> library(jsonlite)
> J <- list()
> J$NetsJSON <- "basic"
> m <- length(F)
> dim <- as.vector(table(B))
> info <- list()
> info$network <- "Marvel"
> info$title <- "The Marvel Cinematic Universe Network"
> info$multirel <- FALSE
> info$directed <- TRUE
> info$mode <- 2
> info$org <- 1
> info$simple <- TRUE
> info$nNodes <- sum(dim)
> info$dim <- dim
> info$nArcs <- m
> info$nEdges <- 0
> info$temporal <- FALSE
> info$time <- list()
> info$meta <- list()
> J$info <- info
> J$nodes <- data.frame(id=1:82,lab=names,mode=as.integer(B))
> J$links <- data.frame(type="arc",n1=as.integer(F),n2=as.integer(T),w=1)
> str(J)
List of 4
 $ NetsJSON: chr "basic"
 $ info    :List of 14
  ..$ network : chr "Marvel"
  ..$ title   : chr "The Marvel Cinematic Universe Network"
  ..$ multirel: logi FALSE
  ..$ directed: logi TRUE
  ..$ mode    : num 2
  ..$ org     : num 1
  ..$ simple  : logi TRUE
  ..$ nNodes  : int 82
  ..$ dim     : int [1:2] 59 23
  ..$ nArcs   : int 202
  ..$ nEdges  : num 0
  ..$ temporal: logi FALSE
  ..$ time    : list()
  ..$ meta    : list()
 $ nodes   :'data.frame':       82 obs. of  3 variables:
  ..$ id  : int [1:82] 1 2 3 4 5 6 7 8 9 10 ...
  ..$ lab : chr [1:82] "Bruce Banner Hulk" "Clint Barton Hawkeye" "Phil Coulson" "Nick Fury" ...
  ..$ mode: int [1:82] 1 1 1 1 1 1 1 1 1 1 ...
 $ links   :'data.frame':       202 obs. of  4 variables:
  ..$ type: chr [1:202] "arc" "arc" "arc" "arc" ...
  ..$ n1  : int [1:202] 1 1 2 3 3 3 3 4 4 4 ...
  ..$ n2  : int [1:202] 60 61 61 62 63 64 61 63 65 61 ...
  ..$ w   : num [1:202] 1 1 1 1 1 1 1 1 1 1 ...
> js <- file("./json/marvel.json",encoding="UTF-8")
> write(toJSON(J),file=js); close(js)
vlado/work/2m/dat/marvel.txt · Last modified: 2023/01/08 01:52 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki