christophergandrud / networkd3 Goto Github PK
View Code? Open in Web Editor NEWD3 JavaScript Network Graphs from R
Home Page: http://christophergandrud.github.io/networkD3
D3 JavaScript Network Graphs from R
Home Page: http://christophergandrud.github.io/networkD3
Hi
I didn't found any function to create directed Networks . Is their any function to generate directed networks ?
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.
Hi,
the node size is not properly restored after mouseover.
In forceNetwork.js, l. 187, in mouseout, the nodeSize(d) is increase by 2, it should not.
Thanks again
Pascal
More prominently document 0 base
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 :)
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):
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.
I notice that there is argument for zooming the tree graph.
Is there any solution for it?
Thank in advance
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.
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.
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
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
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.
Hello,
Would it be possible to color the links in Sankey plots?
Maybe this Gist by @timelyportfolio can help...
Thank you!
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?
I would love to see something like this on networkD3
Thanks!
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:
With the js already written, how hard is it to get this up and running with the htmlwidgets?
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.
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
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
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?
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
Something like this: http://bl.ocks.org/d3noob/5141278
I wonder if it makes sense to bake this into the existing forceNetwork
function?
Also, how much Javascript hacking would be involved?
Am I right in thinking that currently there's no way to display all your node labels at the same time on a forceNetwork?
The mouseover effect is really good for large graphs, but on smaller ones it would be useful to see all the information at once.
Thanks!
Is there a simple way to add edge labels? Looks like it is possible via the JavaScript?
http://stackoverflow.com/questions/18316056/d3-js-force-layout-edge-label-placement-rotation
http://jsfiddle.net/nrabinowitz/VYaGg/2/
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
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?
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?
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:
Thanks,
Charles
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.
With simpleNetwork
and treeNetwork
font size is set by fontSize
, for sankeyNetwork
and forceNetwork
it is fontsize
. Not a dealbreaker, simply a coding inconvenience. Thanks for the great package, BTW.
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
I would like the position of nodes to be constrained within the rectangular bounds of the containing SVG element, as in the example http://bl.ocks.org/mbostock/1129492
Thanks!
FYI. I submitted this issue to stackoverflow.
http://stackoverflow.com/questions/30446519/unable-to-vary-linkdistance-in-network-graph-created-using-forcenetwork-of-netwo
I got an answer that suggested a bug in d3js.
http://stackoverflow.com/a/30448047/2140956
I have submitted this as an issue to d3js.
d3/d3#2451
Is this a way to create a graph that is a "sub-class" of an existing graph type ? Say we want to expand on the simpleNetwork to have our own handlers, is there a recommended way to do this?
Thanks
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>
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!
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!
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.
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
Are there plans to implement an input$last_node_clicked (like from DT htmlwidget) or similar functionality to expose user input to the graph to Shiny?
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.
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
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
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?
It will be great if the nodes have labels displayed by default, apart from displaying labels on hovering over the node.
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.