Giter Club home page Giter Club logo

networkd3's Introduction

D3 JavaScript Network Graphs from R

Development version: 0.4.9000 CRAN Version Build Status CRAN Monthly Downloads CRAN Total Downloads

This README includes information on set up and a number of basic examples. For more information see the package's main page.

Usage

Here's an example of simpleNetwork:

library(networkD3)

# Create fake data
src <- c("A", "A", "A", "A", "B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
networkData <- data.frame(src, target)

# Plot
simpleNetwork(networkData)

Here's forceNetwork:

# Load data
data(MisLinks)
data(MisNodes)

# Plot
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
             Target = "target", Value = "value", NodeID = "name",
             Group = "group", opacity = 0.7,
             colourScale = JS("d3.scaleOrdinal(d3.schemeCategory20);"))

Here's sankeyNetwork using a downloaded JSON data file:

# Recreate Bostock Sankey diagram: http://bost.ocks.org/mike/sankey/
# Load energy projection data
URL <- paste0("https://cdn.rawgit.com/christophergandrud/networkD3/",
              "master/JSONdata/energy.json")
Energy <- jsonlite::fromJSON(URL)

# Plot
sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
             Target = "target", Value = "value", NodeID = "name",
             units = "TWh", fontSize = 12, nodeWidth = 30)

Interacting with igraph

You can use igraph to create network graph data that can be plotted with networkD3. The igraph_to_networkD3 function converts igraph graphs to lists that work well with networkD3. For example:

# Load igraph
library(igraph)

# Use igraph to make the graph and find membership
karate <- make_graph("Zachary")
wc <- cluster_walktrap(karate)
members <- membership(wc)

# Convert to object suitable for networkD3
karate_d3 <- igraph_to_networkD3(karate, group = members)

# Create force directed network plot
forceNetwork(Links = karate_d3$links, Nodes = karate_d3$nodes, 
             Source = 'source', Target = 'target', NodeID = 'name', 
             Group = 'group')

Saving to an external file

Use saveNetwork to save a network to stand alone HTML file:

library(magrittr)

simpleNetwork(networkData) %>% saveNetwork(file = 'Net1.html')

Note

networkD3 began as a port of d3Network package to the htmlwidgets framework. d3Network is no longer supported.

networkd3's People

Contributors

agoldst avatar bwlewis avatar cashoes avatar christophergandrud avatar cjyetman avatar csese avatar edwindj avatar ellisp avatar garthtarr avatar giko45 avatar jjallaire avatar jrowen avatar kevinykuo avatar kobakhit avatar ltrgoddard avatar octaviancorlade avatar ppernot avatar rohdek avatar sirallen avatar teshomem avatar timelyportfolio avatar tomecki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

networkd3's Issues

Click event

Hi Christopher,
This is a beautiful addition to the R libraries.

I have been wondering how to distinguish click/touch events.
Currently a click selects the node so the text expands and you can drag the network around by the node.

I would also like to be able to click to select a node, execute javascript window.open code to open a new browser tab with more info about the selected node.

Maybe a double-click (long touch)?

I have done something similar with rCharts::Highcharts with a slngle click/touch in the PlotOptions parameter.

Do you have a suggestion of how to do this in your beautiful NetworkD3?

Thank you again,
Matt

auto-convert `dendrogram` and `hclust` in `treeNetwork()`

While I am working on other trees, I started to question why the need for the explicit conversion from the user when passing hclust and dendrogram to treeNetwork().

treeNetwork( as.treeNetwork(hc) )

Since you have so nicely provided the helpful as.treeNetwork for the conversion, I think it would be great to check for dendrogram or hclust class and then automatically convert to make it even easier for the R user. I'm happy to do a pull for this if deemed worthwhile and not concerned about unintended consequences that I might be missing.

Base 0

More prominently document 0 base

How to specify node colours?

Is it possible to specify node colours? I read some documentation that suggested this was explained in a readme file but I cannot find instructions for node colour.

Thank you!

Tim

FR: control the opacity of non-hovered text in forceNetwork

Currently the text of node labels that do not have the mouse hovering over them is set to zero by:

      .style("opacity", 0)

I'd like to be able to have all the text showing as ghosts, retaining the current behaviour of expanding and becoming opacity 1 when hovered over. This could be done by adding an argument opacityUnclicked to the R function and passing through for use like:

      .style("opacity", options.opacityUnclicked)

Is this desirable? Happy to submit a pull request.

forceNetwork output not displayed in Firefox

Hi,

the Javascript console in Firefox complains about an unknown "redraw" function.
In fact, the function is defined just after being called in forceNetwork.js (l.84-90).
Shifting the call after the definition solves the problem for me.

There are also a few missing semi-columns in this file...

Thanks for this great package

Pascal

Multiple Groups

First let me say that networkD3 is awesome and saving me a ton of time.

Second, I was wondering if there is a way to assign multiple group columns through the node dataframe. I am new to networkD3 and trying to assign multiple attributes to each node so I can, later, use shiny to pull the various nodes based on their attributes in an interactive network model.

Thanks!

Issues Creating Force Directed Graph

The script runs with no errors, but no graph appears in viewer in R Studio. Pretty basic usage as you can see below. I'm using two csv files.

forceNetwork(Links = force_links, Nodes = force_nodes, Source = "source", Target = "target", Value = "value", NodeID = "name", Nodesize = "size", Group = "group", fontSize = 18, fontFamily = "serif")

source,target,value
0,4,2
0,5,2
0,7,2
0,8,2
0,9,2
0,10,2
0,11,2
0,12,2
0,13,2
0,16,2
0,17,2
1,12,2
1,15,2
1,4,2
1,16,2
1,7,2
1,5,2
1,13,2
2,5,2
2,14,2
2,13,2
2,16,2
2,7,2
2,12,2
2,4,2
2,15,2

name,group,size
Person1,0,10
Person2,1,10
Person3,2,10
Task1,3,20
Task2,4,20
Task3,5,20
Task4,6,20
Task5,7,20
Task6,8,20
Task7,9,20
Task8,10,20
Task9,11,20
Task10,12,20
Task11,13,20
Task12,14,20
Task13,15,20

Feature request: Phylogram with already written D3 code

Hey,
I am doing a hierarchical clustering with a few hundred objects and I'm trying to find a nifty way to visualize the clustering and allow someone to play around with parameters and possibly zoom in and out. I've just started looking into how to make a Phylogram and I think it might be a good addition to networkD3. The following are examples of the d3 already implemented:

I have literally zero experience with javascript and d3 so I have absolutely no idea what I'm doing. I'm just trying to replicate what's been done already in networkD3 and patch in the stuff above.

The basic issues:

  1. Considering that newick.js is already written, really it comes down to just passing the newick string. In R, ape::write.tree does that to a phylo object.
  2. Other than that, it's just piecing together the htmlwidgets components I guess. I think I have the necessary .R file together but the .js file for htmlwidgets is harder for me to figure out. For one, since the code for the phylogram is already written, it'd be nice to just call the functions but I just don't see how it's done.

With the js already written, how hard is it to get this up and running with the htmlwidgets?

Feature request: node shape parameter

Thank you for this great package! I have a feature request to have function parameters for forceNetwork or simpleNetwork that control the size and shape of the nodes. One might want, for example, the color to be based on Group, the size to be based on another nodal attribute, and the shape to be based on a third. Thank you.

change underlying graph in shiny?

This is great work ... but I just wasted an evening thinking I could change the underlying graph in shiny using shinytable, which would be even greater - I thought I would be able to edit the nodes and edge information in a spreadsheet and see the graph change in real time but I have come to the conclusion it won't work, will it? All your examples don't change the underlying graph, only the presentation. Any ideas on how that might be possible?

add TreeColors.js for better tree colors

One of our own from the rstats community (@mtennekes & @edwindj) did this fine research on treemap coloring presented at visWeek 2014 and implemented in the R pkg treemap. Based on this research, @e- made TreeColors.js. Adding this to tree visualizations is as simple as

including the treecolors.min.js in the yaml lines

apply colors similar to the layout like in lines

var additive = TreeColors("add") // could also be subtract
additive(root)  // add a color object (HCL) to all the nodes

then in the styling like in lines

d3.selectAll(".node circle")
  .style("fill", function(d){return d3.hcl(d.color.h,d.color.c,d.color.l)})

I think this is a really nice addition. I guess the question in my mind is do we make this default behavior or do we make it an option with a helper function?

image

Legend and Radius in force network.

Hi, I would like to know if it would be possible to give the user the chance to add a legend and give a radius to the nodes.
I have modified the javascript and added the following lines on my code to have those features.

forceNetwork.R file:
(Added the Nodesize parameter)
forceNetwork <- function(Links, Nodes, Source, Target, Value, NodeID,Nodesize,
Group, height = NULL, width = NULL, colourScale = "d3.scale.category20()",
fontsize = 7, linkDistance = 50,
linkWidth = "function(d) { return Math.sqrt(d.value); }", charge = -120,
linkColour = "#666",opacity = 0.6)
{
# Subset data frames for network graph
if (!is.data.frame(Links)){
stop("Links must be a data frame class object.")
}
if (!is.data.frame(Nodes)){
stop("Nodes must be a data frame class object.")
}
if (missing(Value)){
LinksDF <- data.frame(Links[, Source], Links[, Target])
names(LinksDF) <- c("source", "target")
}
else if (!missing(Value)){
LinksDF <- data.frame(Links[, Source], Links[, Target], Links[, Value])
names(LinksDF) <- c("source", "target", "value")
}

if (!missing(Nodesize)){
        NodesDF <- data.frame(Nodes[, NodeID], Nodes[, Group], Nodes[, Nodesize])
        names(NodesDF) <- c("name", "group", 'nodesize')
}else{
        NodesDF <- data.frame(Nodes[, NodeID], Nodes[, Group])
        names(NodesDF) <- c("name", "group")    
}

Javascript file forceNetwork.js:

function nodeSize(nodesize) {
return Math.sqrt(nodesize)*6
}

node.append("circle")
.attr("r", function(d){return nodeSize(d.nodesize);})
.style("stroke", "#fff")
.style("opacity", options.opacity)
.style("stroke-width", "1.5px");

var legendRectSize = 18;
var legendSpacing = 4;

var legend = svg.selectAll('.legend')
.data(color.domain())
.enter()
.append('g')
.attr('class', 'legend')
.attr('transform', function(d, i) {
var height = legendRectSize + legendSpacing;
var offset = height * color.domain().length / 2;
var horz = legendRectSize;
var vert = i * height+4;
return 'translate(' + horz + ',' + vert + ')';
});

    legend.append('rect')                                     
      .attr('width', legendRectSize)                          
      .attr('height', legendRectSize)                         
      .style('fill', color)                                   
      .style('stroke', color);                                

    legend.append('text')                                     
      .attr('x', legendRectSize + legendSpacing)              
      .attr('y', legendRectSize - legendSpacing)              
      .text(function(d) { return d; }); 

You finally get the following layout:
image

Thanks,
Charles

Won't create proper visualization more than once.

I've had trouble producing a visualization more than one time. When I create the visualization the first time it produces an html document that shows the expected visualization, but when I make an edit for something such as plot size it won't then reproduce the plot instead the html opens to a blank webpage despite the fact that it produces the expected code. I'm a little inexperienced with web development, but when I open the html.file in brackets part of the code that r generates isn't colored correctly (note midway down the page the text turns black):
bracketsscreenshot
Initial plots that work do not have the same coloring problem when opened in brackets. This might be a symptom of the problem, but like I said I'm not well versed in web development. This same problem happens when I create a plot in shiny too. It works once but won't recreate the plot if I make additional edits or rerun shiny.

Feature request: Mouseover for edges for forceNetwork graph

Hi Chris,
Thanks for your great work on this package.

I am playing with forceNetwork graphs to visualize RDF. Would it be possible to add mouseover labels for the edges as part of the links data set in a future version? Someone had also mentioned the addition of arrows, which could also be helpful, possibly added by always pointing from source to target if the option is on? If there is another way to accomplish either of these functions please let me know.

Cheers,

Tim

Sankey Diagram Will Not Plot

Hello,
Am relatively new to R and was trying to plot a Sankey diagram using the networkD3 library. However, all I get is a blank screen. The diagram is supposed to show the flow of infections between age groups (by gender). My code is as below:

library(RCurl)
library(networkD3)

edges <- read.csv(curl("https://raw.githubusercontent.com/kilimba/data/master/infection_flows.csv"),stringsAsFactors = FALSE )

nodes = data.frame(ID = unique(c(edges$Source, edges$Target)))

nodes$indx =0
for (i in 1:nrow(nodes)){
  nodes[i,]["indx"] = i - 1
}

edges2 <- merge(edges,nodes,by.x = "Source",by.y = "ID")
edges2$Source <-NULL
names(edges2) <- c("target","value","source")
edges2 <- merge(edges2,nodes,by.x = "target",by.y = "ID")
edges2$target <- NULL
names(edges2) <- c("value","source","target")

nodes$indx <- NULL
# Plot
sankeyNetwork(Links = edges2, Nodes = nodes,
              Source = "source", Target = "target",
              Value = "value", NodeID = "ID",
              width = 700, fontsize = 12, nodeWidth = 30)

Any help greatly appreciated.
Tumaini

Blank page when using sankeyNetwork

Hi,

I tested sankeyNetwork with the default Energy example and it works fine but I'm trying to use the function with my own data but I have not been very successful.

This is my data:

dput(tabDF)

structure(list(party = 1:72, group = c(1L, 64L, 1L, 64L, 1L, 
64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 
64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 
64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 
64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 
64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L, 1L, 64L), value = c(78L, 
0L, 5L, 1L, 16L, 0L, 6L, 79L, 0L, 16L, 33L, 2L, 7L, 2L, 0L, 2L, 
0L, 0L, 3L, 3L, 9L, 86L, 0L, 0L, 0L, 0L, 0L, 0L, 30L, 0L, 0L, 
1L, 0L, 0L, 0L, 1L, 6L, 9L, 20L, 0L, 2L, 0L, 7L, 19L, 0L, 3L, 
2L, 6L, 1L, 0L, 0L, 2L, 0L, 0L, 12L, 0L, 0L, 9L, 0L, 1L, 0L, 
4L, 0L, 66L, 5L, 0L, 0L, 0L, 1L, 0L, 0L, 0L)), .Names = c("party", 
"group", "value"), row.names = c(NA, -72L), class = "data.frame")

dput(nodes)

structure(list(name = c("DEM", "PCdoB", "PDT", "PEN", "PFL", 
"PHS", "PL", "PMDB", "PMN", "PP", "PPB", "PPS", "PR", "PRB", 
"PRONA", "PROS", "PRP", "PRTB", "PSB", "PSC", "PSD", "PSDB", 
"PSDC", "PSL", "PSOL", "PST", "PSTU", "PT", "PTB", "PTC", "PTdoB", 
"PTN", "PV", "S.Part.", "S.PART.", "SD")), .Names = "name", row.names = c(NA, 
-36L), class = "data.frame")

And this is how I'm running the function:

sankeyNetwork(Links=tabDF,Nodes=nodes,Source="party",Target="group",
              Value="value",NodeID="name",fontsize=12,nodeWidth=30)

But all I get is a blank page, what am I doing wrong? This is the page source:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script src="lib/htmlwidgets-0.3.2/htmlwidgets.js"></script>
<script src="lib/d3-3.5.2/d3.min.js"></script>
<script src="lib/sankey-1/sankey.js"></script>
<script src="lib/sankeyNetwork-binding-0.1.2.1/sankeyNetwork.js"></script>

</head>
<body style="background-color:white;">
<div id="htmlwidget_container">
  <div id="htmlwidget-7975" style="width:960px;height:500px;" class="sankeyNetwork"></div>
</div>
<script type="application/json" data-for="htmlwidget-7975">{ "x": {
 "links": {
 "source": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72 ],
"target": [ 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64 ],
"value": [ 78, 0, 5, 1, 16, 0, 6, 79, 0, 16, 33, 2, 7, 2, 0, 2, 0, 0, 3, 3, 9, 86, 0, 0, 0, 0, 0, 0, 30, 0, 0, 1, 0, 0, 0, 1, 6, 9, 20, 0, 2, 0, 7, 19, 0, 3, 2, 6, 1, 0, 0, 2, 0, 0, 12, 0, 0, 9, 0, 1, 0, 4, 0, 66, 5, 0, 0, 0, 1, 0, 0, 0 ] 
},
"nodes": {
 "name": [ "DEM", "PCdoB", "PDT", "PEN", "PFL", "PHS", "PL", "PMDB", "PMN", "PP", "PPB", "PPS", "PR", "PRB", "PRONA", "PROS", "PRP", "PRTB", "PSB", "PSC", "PSD", "PSDB", "PSDC", "PSL", "PSOL", "PST", "PSTU", "PT", "PTB", "PTC", "PTdoB", "PTN", "PV", "S.Part.", "S.PART.", "SD" ] 
},
"options": {
 "NodeID": "name",
"colourScale": "d3.scale.category20()",
"fontsize":                12,
"nodeWidth":                30,
"nodePadding":                10 
} 
},"evals": [  ] }</script>
<script type="application/htmlwidget-sizing" data-for="htmlwidget-7975">{ "viewer": {
 "width":               450,
"height":               350,
"padding":                15,
"fill": true 
},"browser": {
 "width":               960,
"height":               500,
"padding":                75,
"fill": true 
} }</script>
</body>
</html>

Embedding simpleNetwork in Slidify deck

I've tried a slew of different things and cannot get the simpleNetwork to render in a Slidify deck when using runDeck(). I have added "ext_widgets : {networkD3: [htmlwidgets]}", "ext_widgets : {networkD3: [htmlwidgets/lib]}", "ext_widgets : {networkD3: [htmlwidgets/lib/d3-3.5.2]}" and all combinations there of to my yaml. I have also added simpleNetwork to my widgets line. I've tried using slidifyUI with htmlOuput, simpleNetworkOutput, or tags$div(id='networkGraph' class='shiny-html-output simpleNetwork networkD3') in the mainPanel( ) section. Nothing seems to be working and I can't figure out why. How do you incorporate this package into a slidify deck?

Thanks in advance!

Feature Request: link strength

It would be great to be able to specify the link strength, force.linkStrength([strength]). For the forceNetwork. perhaps a nother column on the link dataframe could be used to assign forces? In my case I have two types of links and would like to be able to specify strong and weak.

unused argument (units = "TWh")

Hi,
from your example page:

URL <- paste0(
        "https://cdn.rawgit.com/christophergandrud/networkD3/",
        "master/JSONdata/energy.json")
Energy <- jsonlite::fromJSON(URL)
# Plot
sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
             Target = "target", Value = "value", NodeID = "name",
             units = "TWh", fontSize = 12, nodeWidth = 30)

gives the error

Error in sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",  : 
  unused argument (units = "TWh")

Removing units works:

URL <- paste0(
        "https://cdn.rawgit.com/christophergandrud/networkD3/",
        "master/JSONdata/energy.json")
Energy <- jsonlite::fromJSON(URL)
# Plot
sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
             Target = "target", Value = "value", NodeID = "name",
             fontSize = 12, nodeWidth = 30)

This is networkD3_0.2.1 under PRO 3.2.1.
Cheers
Tobias

Rendering graph in Rhtml

I'm trying to reproduce this graph using networkD3. The current code is here and is self-contained. It uses Rhtml with knitr. The relevant code chunk is:

<!--begin.rcode makeGraph, echo=FALSE, message=FALSE    
forceNetwork(Links = links, 
             Nodes = nodes,
             Source = "source",
             Target = "target", 
             Value = "value",
             Group = "Group",
             colourScale = "d3.scale.category10()",
             NodeID = "name",
             charge = -50,
             fontsize = 5,
             linkDistance = 25)
    end.rcode-->  

(the graph looks great using saveNetwork).

Right now, the JSON for options, evals, nodes and links is written out (evals is empty) but no graph.

Are there different chunk options to use?

Thanks,

Max

click node to expand - session$registerDataObj ?

Can a node execute a detail query to add more nodes from elsewhere via Ajax back to R via shiny? Looks like we have to load all nodes and edges at once and for performance reasons this may not be feasible.

shiny, forceNetwork(..., zoom = TRUE) in browser

Hello, Christopher!

My application works perfectly wel in browser:

shiny::runGitHub('zefmud/MPs_network')

But it stop showing forceNetwork in browser if I use "zoom = TRUE"

shiny::runGitHub('zefmud/MPs_network_zoom')

Is there any way too zoom while viewing forceNetwork in browser?

Thank you for the wonderful package :)

feature request: spatial node grouping by group membership?

It would be really neat to be able to group nodes based on their group membership - possibly by having attraction for within group members and repulsion for non-group members - it would make this package ideal for designing neural net diagrams. thanks for the neat package.

Zoom feature for tree graph

I notice that there is argument for zooming the tree graph.
Is there any solution for it?
Thank in advance

Package Bloat? A function to add group and link strength to a simpleNetwork edgelist?

I want write a function that could be used to take the edgelists for simpleNetwork and make it cool for forceNetwork. I've got a script so far:

# Load package
library(networkD3)

# Create fake data
src <- c("A", "A", "A", "A",
         "B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J",
            "E", "F", "G", "H", "I")
networkData <- data.frame(src, target)

#Data is organized for simpleNetwork()
#simpleNetwork(networkData)

#Assume a dataframe with a group for each node
exampleNodes <- data.frame(node = LETTERS[1:10], group = c(1,1,1,1,2,2,2,3,3,4))

networkData$src <- as.numeric(factor(networkData$src, levels(exampleNodes$node)))  -1
networkData$target <- as.numeric(factor(networkData$target, levels(exampleNodes$node))) -1

exampleLinks <- cbind(networkData, link_strength = sample(1:3, 9, replace = T))

forceNetwork(Links = exampleLinks, Nodes = exampleNodes,
             Source = "src", Target = "target", 
             Value = "link_strength", NodeID = "node",
             Group = "group", opacity = 0.8)

Thoughts? Criticism?

Sankey doesn't render with Shiny

Hi,

Great to see this update of your package! It appears the Sankey code has some rendering issues in Shiny, at least in my setup. Based on the example code I've added this in ui.r:

 sankeyNetworkOutput('networkPlot', width = "100%", height = "600px")

and this in server.r:

output$networkPlot <- renderSankeyNetwork({

      sankeyNetwork(Links = EngLinks, Nodes = EngNodes, Source = "source",
                    Target = "target", Value = "value", NodeID = "name", width = 1600,
                    height = 800, fontsize = 12, nodeWidth = 15, nodePadding = 10)

  })

When running the app no output is shown however :-( Your sankeyNetwork example code also misses some lines at the end by the way.

When I run the code block

sankeyNetwork(Links = EngLinks, Nodes = EngNodes, Source = "source",
                    Target = "target", Value = "value", NodeID = "name", width = 1600,
                    height = 800, fontsize = 12, nodeWidth = 15, nodePadding = 10)

without Shiny it does display the diagram correctly.

The forceNetwork and simpleNetwork examples run fine in Shiny, with exception of the zoom option, but I noticed you already filed this item yourself.

kind regards Herman

ps: for the forceNetwork it would be nice to be able to optionally show the labels. Now the opacity of the labels is always 0 and changes to 1 on hover. Furthermore, I think it would be extremely useful to have some word wrapping on long labels. I know D3 lacks a bit in this area as SVG doesn't (yet) support this natively .

Session info:
R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252 LC_MONETARY=Dutch_Netherlands.1252
[4] LC_NUMERIC=C LC_TIME=Dutch_Netherlands.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] networkD3_0.1 d3Network_0.5.1 RCurl_1.95-4.1 bitops_1.0-6 shiny_0.10.1

loaded via a namespace (and not attached):
[1] caTools_1.17 digest_0.6.4 htmltools_0.2.6 htmlwidgets_0.2.2 httpuv_1.3.0 plyr_1.8.1 Rcpp_0.11.2
[8] rjson_0.2.14 RJSONIO_1.2-0.2 tools_3.1.1 whisker_0.3-2 xtable_1.7-3 yaml_2.1.13

Feature request: control shape of nodes

I don't have time to do this right now but am noting it down so I remember for later or to get feedback ("terrible idea, don't clutter it up any further"?). The idea is that eg some nodes would be triangles, some hexagons, etc. - useful for mapping to grouping variables when size and colour are needed for other mappings.

Generic functions and methods (e.g. for igraph)

Thanks for this package!

It would be nice for e.g. simpleNetwork and forceNetwork to have methods for igraph and network objects. I started to write one for igraph. Is anybody working on that?

For methods to work it would be necessary to make at least simpleNetwork and forceNetwork S3 generic functions. Current implementations could become default methods.

Are you interested in such features?

forceNetwork edges not displaying

I just started working with forceNetwork plots in R (great library by the way!). I am having issues getting edges to render correctly. Nodes appear ok, but I don't see any edges. I was able to replicate the sample plot (MisLinks and MisNodes objects), but the plot with my edge and node files doesn't seem to work correctly. Here's the code I used to create the network plot:

forceNetwork(Links = mod.edges.d3, Nodes = mod.nodes.d3,
Source = "source", Target = "target",
Value = "value", NodeID = "name", linkColour = "black",
Group = "group", opacity = 0.8)

and a sample of my edge and node files:

head(mod.edges.d3)
source target value
1 1 29 5
2 1 37 4
3 1 126 2
4 1 126 3
5 2 16 3
6 2 20 3
head(mod.nodes.d3)
name group
1 g_1 1
2 g_2 1
3 g_3 1
4 g_4 1
5 g_5 1
6 g_6 1

I wasn't sure how to start targets in my edge file at '0'. I can provide the full edge and node files as well. any insight you might have would be greatly appreciated.

Best,
Sri

radialNetwork function

I integrated a new function radialNetwork for use in networkD3 as explained in this post. Happy to submit pull after you have had time to look at it, or I can easily make it into a separate package.

explore hierarchical reusable d3.charts for multiple layouts and behaviors

This project d3.chart.layout provides nearly all the hierarchical layouts of d3 with the reusability of d3.chart and nice built-in zoom and collapse. It seemed to be much better than hand-building each of these layouts, so I started to explore in this branch feature/d3.chart.layout and added function hierNetwork to access these. Here is a demo using a hclust and flare.json and the code to reproduce is in this gist (thanks gistr).

Before I flesh it out, I wanted to make sure that it would be deemed an acceptable addition. @jjallaire & @christophergandrud , what do you think?

Internet Explorer Restriction message - External sand alone HTML file

Hello,

When generating standalone external HTML files and loading these in IE (Version 9) I get a warning about blocked content... "

Internet Explorer restricted this webpage from running scripts or ActiveX controls.

Do you know what IE would find "dangerous" from the generated output ?

Thanks.

default font

Hello,

Really digging networkD3 (getting into htmlwidgets is one of my new-year's resolutions).

Considering Sankey diagrams, but I think this may apply to the others, I see that the font family is hard-coded.

For example:
https://github.com/christophergandrud/networkD3/blob/master/inst/htmlwidgets/sankeyNetwork.js#L121
(wrong link before)

Would you consider removing the serif specification, so that the browser (or css) could be used to specify the font?

Happy to make a PR, if you like.

Thanks,

Ian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.