christophergandrud / christophergandrud/networkD3

re-index nodes from 0 if necessary

Open
#190 1 comment 0 reactions 0 assignees View on GitHub
enhancement forceNetwork
Dominant language
R
Stars
659
Forks
259
PR merge metrics
No merged PRs in 30d

Description

The error/warning "It looks like Source/Target is not zero-indexed. This is required in JavaScript and so your plot may not render." seems to catch and confuse many people. This seems like something the R functions should be able to check for and fix on their own if necessary. The current version of simpleNetwork() already handles this automatically. It seems odd to me that, in the code below, the 1st one fails while the 2nd one works, the only change being that 1 was subtracted from the node ids in the Links data frame...
```r
forceNetwork(Links = data.frame(source = c(1,1,2), target = c(2,3,4)),
Nodes = data.frame(name = c("A", "B", "C", "D"), group = 1),
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'group')

forceNetwork(Links = data.frame(source = c(1,1,2) - 1, target = c(2,3,4) - 1),
Nodes = data.frame(name = c("A", "B", "C", "D"), group = 1),
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'group')
```

Is there any reason we can't automatically re-index as below (or maybe a bit more cautiously)...
```r
Links <- data.frame(source = c(2,2,3), target = c(3,4,5))
Links <- Links - min(unlist(Links))
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.