Search code examples
rnetworkd3

R networkD3 change node IMG


I would like to replace the basic node image to a custom jpg in networkD3 package in R.

Here is an example:

library(networkD3)

# Load data
data(MisLinks)
data(MisNodes)

# Plot
forceNetwork(Links = MisLinks, Nodes = MisNodes,
            Source = "source", Target = "target",
            Value = "value", NodeID = "name",
            Group = "group", opacity = 0.8)

So I would like to create a node like this: enter image description here

Instead of this:

enter image description here

Is it possible?


Solution

  • I would like to replace the basic node image to a custom jpg in networkD3 package in R. [...] For me it is also good with any other interacive R network package

    For example, you could do

    library(networkD3)
    library(visNetwork)
    library(dplyr)
    data(MisLinks)
    data(MisNodes)
    visNetwork(
      MisNodes %>% 
        rename("label"=name) %>% 
        mutate(id = seq_len(nrow(MisNodes))-1),
      MisLinks %>% 
        rename("from"=source, "to"=target)
    ) %>%
      visNodes(
        shape = "image", 
        image = "http://cdn0.iconfinder.com/data/icons/octicons/1024/mark-github-128.png"
      )
    

    giving you

    enter image description here