Skip to content

Commit 6dc7368

Browse files
committed
merge
Merge branch 'master' into moreFunctions Conflicts: R/sankeyNetwork.R
2 parents 8967c43 + 836f985 commit 6dc7368

File tree

15 files changed

+50
-436
lines changed

15 files changed

+50
-436
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Title: Tools for creating D3 JavaScript network, tree, dendrogram, and Sankey
55
Description: This packages is intended to make it easy to create D3 JavaScript
66
network, tree, dendrogram, and Sankey graphs from R using data frames.
77
Version: 0.7.0
8-
Date: 2014-08-13
8+
Date: 2014-08-15
99
Author: Christopher Gandrud and J.J. Allaire
1010
Maintainer: Christopher Gandrud <christopher.gandrud@gmail.com>
1111
URL: http://github.com/christophergandrud/networkD3/

NAMESPACE

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ export(forceNetworkOutput)
66
export(renderForceNetwork)
77
export(renderSankeyNetwork)
88
export(renderSimpleNetwork)
9-
export(renderTreeNetwork)
109
export(sankeyNetwork)
1110
export(sankeyNetworkOutput)
1211
export(saveNetwork)
1312
export(simpleNetwork)
1413
export(simpleNetworkOutput)
15-
export(treeNetwork)
16-
export(treeNetworkOutput)
1714
importFrom(htmlwidgets,shinyRenderWidget)
1815
importFrom(htmlwidgets,shinyWidgetOutput)
1916
importFrom(plyr,ldply)
2017
importFrom(rjson,fromJSON)
21-
importFrom(rjson,toJSON)
22-
importFrom(whisker,whisker.render)

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Version 0.7
2+
3+
- `sankeyNetwork` added.
4+
5+
- `colourScale` argument added to `forceNetwork` and `sankeyNetwork` to allow
6+
the user to change the node colour scale.

R/forceNetwork.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#' \code{Nodes} data frame.
2121
#' @param height numeric height for the network graph's frame area in pixels.
2222
#' @param width numeric width for the network graph's frame area in pixels.
23+
#' @param colourScale character string specifying the categorical colour
24+
#' scale for the nodes. See
25+
#' \url{https://github.com/mbostock/d3/wiki/Ordinal-Scales}.
2326
#' @param fontsize numeric font size in pixels for the node text labels.
2427
#' @param linkDistance numeric or character string. Either numberic fixed
2528
#' distance between the links in pixels (actually arbitrary relative to the
@@ -71,7 +74,8 @@
7174
#'
7275
#' @export
7376
forceNetwork <- function(Links, Nodes, Source, Target, Value, NodeID,
74-
Group, height = NULL, width = NULL, fontsize = 7, linkDistance = 50,
77+
Group, height = NULL, width = NULL, colourScale = "d3.scale.category20()",
78+
fontsize = 7, linkDistance = 50,
7579
linkWidth = "function(d) { return Math.sqrt(d.value); }", charge = -120,
7680
linkColour = "#666",opacity = 0.6, zoom = FALSE)
7781
{
@@ -97,6 +101,7 @@ forceNetwork <- function(Links, Nodes, Source, Target, Value, NodeID,
97101
options = list(
98102
NodeID = NodeID,
99103
Group = Group,
104+
colourScale = colourScale,
100105
fontsize = fontsize,
101106
clickTextSize = fontsize * 2.5,
102107
linkDistance = linkDistance,

R/sankeyNetwork.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#' data frame.
1919
#' @param height numeric height for the network graph's frame area in pixels.
2020
#' @param width numeric width for the network graph's frame area in pixels.
21+
#' @param colourScale character string specifying the categorical colour
22+
#' scale for the nodes. See
23+
#' \url{https://github.com/mbostock/d3/wiki/Ordinal-Scales}.
24+
#' @param fontsize numeric font size in pixels for the node text labels.
2125
#' @param nodeWidth numeric width of each node.
2226
#' @param nodePadding numeric essentially influences the width height.
2327
#'
@@ -43,7 +47,8 @@
4347
#' @export
4448

4549
sankeyNetwork <- function(Links, Nodes, Source, Target, Value, NodeID,
46-
height = NULL, width = NULL, fontsize = 7, nodeWidth = 15, nodePadding = 10)
50+
height = NULL, width = NULL, colourScale = "d3.scale.category20()",
51+
fontsize = 7, nodeWidth = 15, nodePadding = 10)
4752
{
4853
# Subset data frames for network graph
4954
if (class(Links) != "data.frame"){
@@ -66,6 +71,7 @@ sankeyNetwork <- function(Links, Nodes, Source, Target, Value, NodeID,
6671
# create options
6772
options = list(
6873
NodeID = NodeID,
74+
colourScale = colourScale,
6975
fontsize = fontsize,
7076
nodeWidth = nodeWidth,
7177
nodePadding = nodePadding

R/treeNetwork.R

Lines changed: 0 additions & 150 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Tools for creating D3 JavaScript network graphs from R
22

3+
Version 0.7
4+
35
This is a port of Christopher Gandrud's
46
[d3Network](http://christophergandrud.github.io/d3Network/) package to the
57
[htmlwidgets](https://github.com/ramnathv/htmlwidgets) framework.
@@ -38,7 +40,8 @@ data(MisNodes)
3840
# Plot
3941
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
4042
Target = "target", Value = "value", NodeID = "name",
41-
Group = "group", opacity = 0.4)
43+
Group = "group", opacity = 0.4,
44+
colourScale = "d3.scale.category20b()")
4245
```
4346

4447
Here's `sankeyNetwork` using a downloaded JSON data file:

inst/htmlwidgets/forceNetwork.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ HTMLWidgets.widget({
3535
var width = el.offsetWidth;
3636
var height = el.offsetHeight;
3737

38-
var color = d3.scale.category20();
38+
var color = eval(options.colourScale);
3939

4040
// create d3 force layout
4141
force
@@ -82,7 +82,15 @@ HTMLWidgets.widget({
8282
.attr("class", "link")
8383
.style("stroke", options.linkColour)
8484
.style("opacity", options.opacity)
85-
.style("stroke-width", eval("(" + options.linkWidth + ")"));
85+
.style("stroke-width", eval("(" + options.linkWidth + ")"))
86+
.on("mouseover", function(d) {
87+
d3.select(this)
88+
.style("opacity", 1);
89+
})
90+
.on("mouseout", function(d) {
91+
d3.select(this)
92+
.style("opacity", options.opacity);
93+
});
8694

8795
// draw nodes
8896
var node = svg.selectAll(".node")

inst/htmlwidgets/sankeyNetwork.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ HTMLWidgets.widget({
4242
var width = el.offsetWidth;
4343
var height = el.offsetHeight;
4444

45-
var color = d3.scale.category20();
45+
var color = eval(options.colourScale);
4646

4747
var formatNumber = d3.format(",.0f"),
4848
format = function(d) { return formatNumber(d); }

0 commit comments

Comments
 (0)