1

I am trying to make an interactive website traffic diagram using web traffic data.

Using packages.

It is just a simpleNetwork, however keeps giving me this warning and force closes RStudio.

library(networkD3)
simpleNetwork(data.frame(BWT2012$Visitors, 1:189157, fontSize = 16, nodeColour = "blue", nodeClickColour = "red", textColour = "black", opacity = 0.6, zoom = T))

Warning Message: It looks like Source/Target is not zero-indexed. This is required in Javascript and so your plot may not render.

I have been researching for hours however cannot seem to find how this works. I understand that javascript reads from 0 and r from 1. That is why it is not working.

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56

1 Answers1

4
  1. it is very difficult for anyone to help you because you haven't provided a reproducible example, i.e. we have no idea what your data frame BWT2012 looks like

  2. there seems to be a bug in your code... data.frame(BWT2012$Visitors, 1:189157, fontSize = 16, nodeColour = "blue", nodeClickColour = "red", textColour = "black", opacity = 0.6, zoom = T) will not work no matter what BWT2012 looks like because you're passing elements to the data.frame function that are of different lengths. I suspect you meant for it to be simpleNetwork(data.frame(BWT2012$Visitors, 1:189157), fontSize = 16, nodeColour = "blue", nodeClickColour = "red", textColour = "black", opacity = 0.6, zoom = T), where the first argument of the simpleNetwork() function is a complete data.frame() with BWT2012$Visitors as its first argument and 1:189157 as its second argument, i.e. you intend to pass to the simpleNetwork() function a data frame that has the first column/variable equal to BWT2012$Visitors and the second column equal to 1:189157

  3. Assuming #2 above is correct, the data frame you are trying to pass is telling simpleNetwork that the values in BWT2012$Visitors are the sources of each link, and the values in 1:189157 are the targets of each link. That seems like a very unlikely scenario, so I would make sure you're getting what you think you're getting.

  4. The warning you mention is just a warning... it will not stop the function from running. In many (maybe all since recent changes in ) cases it will still plot the graph, though the results might be unexpected. For instance...

    Source <- c(1, 1, 2)
    Target <- c(2, 3, 3)
    NetworkData <- data.frame(Source, Target)
    simpleNetwork(NetworkData)
    
  5. Using the example from #4, if you wanted to renumber your source and target ids so that they were 0-indexed and avoid the warning, you could do...

    Source <- c(1, 1, 2)
    Target <- c(2, 3, 3)
    Source <- Source - 1
    Target <- Target - 1
    NetworkData <- data.frame(Source, Target)
    simpleNetwork(NetworkData)
    
CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
  • Hi, thank you for commenting. The file I am working with is very large(with a massive 189157 lines). How can I possible upload or show this file to you? – Shahzoda Nasimi Feb 26 '17 at 22:58
  • `library(networkD3) Source <- c(1, 1, 2) Target <- c(2, 3, 3) Source <- Source - 1 Target <- Target - 1 NetworkData <- data.frame(Source, Target) simpleNetwork(NetworkData) simpleNetwork(data.frame(BWT2012$Visitors, 1:189157), fontSize = 16, nodeColour = "blue", nodeClickColour = "red", textColour = "black", opacity = 0.6, zoom = T)` I have tried this with no luck. first time working with R. – Shahzoda Nasimi Feb 26 '17 at 23:02
  • Often you can reduce a large dataset to a smaller one, but still have the same effect to demonstrate the problem... so maybe only the first 5 rows of `BWT2012` would be sufficient to see the problem and/or replicate it. The code you pasted above, excluding the last line which you added in definitely works. Also, I can tell you before you bother struggling... trying to plot 200,000 links with networkD3 is not going to go well... it's simply not designed to handle that many links. – CJ Yetman Feb 27 '17 at 18:23
  • also see here for tips on how to good reproducible examples: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – CJ Yetman Feb 27 '17 at 18:34