By bare-bones I mean other than the arguments indicating the
Data data frame, as well as the
Target variables it only has three arguments:
The data frame you use should have two columns that contain the source and target variables. Here's an example using fake data:
Source <- c("A", "A", "A", "A", "B", "B", "C", "C", "D") Target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I") NetworkData <- data.frame(Source, Target)
width arguments obviously set the graph's frame height and width. You can tell
file the file name to output the graph to. This will create a standalone webpage. If you leave
NULL, then the graph will be printed to the console. This can be useful if you are creating a document using knitr Markdown or (similarly) slidify. Just set the code chunk
results='asis and the graph will be rendered in the document.
Here's a simple example. First load
# Load packages to download d3SimpleNetwork library(digest) library(devtools) # Download d3SimpleNetwork source_gist("5734624")
Now just run the function with the example
NetworkData from before:
d3SimpleNetwork(NetworkData, height = 300, width = 700)
Click here for the fully manipulable version. If you click on individual nodes they will change colour and become easier to see. In the future I might add more customisability, but I kind of like the function's current simplicity.