Learn R Programming

r2d3 (version 1.0)

D3Force: D3 Force

Description

Creates a html file containing json file and a D3.js Force Directed Layout. If you want colours in the force directed layout to represent a group, please ensure the column is labelled "group" in the data frame

Usage

D3Force(JSON, file_out, arrows = FALSE, collision.detect = FALSE, fisheye = FALSE)

Arguments

JSON
A json object
file_out
the location and name for the output html file
arrows
Boolean do you want arrow heads. By default FALSE
collision.detect
Boolean do you want avoid collisions between nodes. By default FALSE
fisheye
Boolean do you want fish eye zooming. By default FALSE

References

Mike Bostock's lovely d3: http://d3js.org/

Examples

Run this code
nodes.df<-data.frame(name=c("Dan", "Digby", "Lex", "Flamer", "Stripey"), age=c(32, 38, 45, 17, 2))
links.df<-data.frame(source=c("Dan", "Digby", "Flamer"), target=c("Lex", "Flamer", "Stripey"))
JSON<-jsonNodesLinks(nodes.df, links.df)
D3Force(JSON, file_out="Force.html")

#With directional arrows
D3Force(JSON, file_out="Force.html", arrows=TRUE))

data(celebs)
colnames(celebs$relationships)<-c('source', 'target')
colnames(celebs$celebs)<-c('name', 'group')
JSON<-jsonNodesLinks(celebs$celebs, celebs$relationships)
D3Force(JSON, file_out="/Users/home/Documents/R_Projects/Force.html")

Run the code above in your browser using DataLab