christophergandrud / d3Network

Tools for creating D3 JavaScript network graphs from R.
http://christophergandrud.github.io/d3Network/
171 stars 56 forks source link

Can't create d3ForceNetwork with own data #9

Closed dkalisch closed 10 years ago

dkalisch commented 10 years ago

Hi Christopher,

Thanks for that package. I tried the examples you provided at your webpage http://christophergandrud.github.io/d3Network/ and they worked fine. However, I tried the same with my own data, but wasn't able to create the d3ForceDirected graph.

I tried this:

Links <- structure(list(source = c(1, 1, 2, 2, 2, 3), target = c(2, 4, 
3, 4, 5, 1), value = c(2, 5, 1, 3, 7, 2)), .Names = c("source", 
"target", "value"), row.names = c(NA, -6L), class = "data.frame")

Nodes <- structure(list(name = structure(1:5, .Label = c("A", "B", "C", 
"D", "E"), class = "factor"), group = c(1, 2, 2, 3, 1)), .Names = c("name", 
"group"), row.names = c(NA, -5L), class = "data.frame")

d3ForceNetwork(Links = Links, Nodes = Nodes, 
                Source = "source", Target = "target", 
                Value = "value", NodeID = "name", 
                Group = "group", width = 550, height = 400, 
                opacity = 0.9, file = '~/Desktop/exm2.html')

The created page doesn't show the graph. Do you have any suggestions? Thanks for your help.

christophergandrud commented 10 years ago

One issue is that the target/values start at 0 rather than 1. I've improved the documentation to clarify this.

Unfortunately, in the course of examining this issue I found what looks to be like a code break caused by a recent update of d3.js. I'll look into this over the next week or so.

Thanks for highlighting these issues.

dkalisch commented 10 years ago

Oh that would be great. I tried it with the 0 as well, although it should not make a difference, but it didn't work either.

Best, Dominik

On 14.10.2013, at 12:10, Christopher Gandrud notifications@github.com wrote:

One issue is that the target/values start at 0 rather than 1. I've improved the documentation to clarify this.

Unfortunately, in the course of examining this issue I found what looks to be like a code break caused by a recent update of d3.js. I'll look into this over the next week or so.

Thanks for highlighting these issues.

— Reply to this email directly or view it on GitHub.

christophergandrud commented 10 years ago

Sorry for the delay. Luckily what I thought was a code break due to an update of d3.js was actually just an issue with my local install. So no worries about that.

Re your code: I modified your code a little bit to the following:

Links <- structure(list(source = c(1, 1, 2, 2, 2, 3), 
                        target = c(0, 4, 3, 4, 0, 1), 
                        value = c(2, 4, 1, 3, 3, 50)), .Names = c("source", 
                        "target", "value"), row.names = c(NA, -6L), class = "data.frame")

Nodes <- structure(list(name = c("A", "B", "C", "D", "E"), 
                        group = c(1, 2, 2, 3, 3)), .Names = c("name", "group"), 
                        row.names = c(NA, -5L), class = "data.frame")

This should work. All I've done is start the target numbering from 0 rather than 1. This will be labeled A in the resulting graph. I also have the name category as character strings rather than factors. Other changes should be superficial.

Just let me know if you still have issues.