-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathREADME.html
More file actions
239 lines (199 loc) · 9.52 KB
/
README.html
File metadata and controls
239 lines (199 loc) · 9.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<title></title>
<script src="README_files/jquery-1.11.0/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="README_files/bootstrap-3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="README_files/bootstrap-3.3.1/js/bootstrap.min.js"></script>
<script src="README_files/bootstrap-3.3.1/shim/html5shiv.min.js"></script>
<script src="README_files/bootstrap-3.3.1/shim/respond.min.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<link rel="stylesheet"
href="README_files/highlight/default.css"
type="text/css" />
<script src="README_files/highlight/highlight.js"></script>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs && document.readyState && document.readyState === "complete") {
window.setTimeout(function() {
hljs.initHighlighting();
}, 0);
}
</script>
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
</style>
<div class="container-fluid main-container">
<div id="description" class="section level1">
<h1>Description</h1>
<div id="network-visualization-using-plotly." class="section level2">
<h2>Network visualization using <a href="https://github.com/ropensci/plotly">Plotly</a>.</h2>
</div>
</div>
<div id="install" class="section level1">
<h1>Install</h1>
<pre class="r"><code>devtools::install_github("dgrapov/networkly.git")</code></pre>
</div>
<div id="examples" class="section level1">
<h1>Examples</h1>
<div id="create-network-edge-list-and-node-attributes" class="section level2">
<h2>Create network <code>Edge List</code> and <code>Node Attributes</code></h2>
<pre class="r"><code>#set up network structure
conn<-1 # average number of conenctions per variable
nodes<-10 # number of variables
net_size<-conn*nodes
edge_type<-2 # number of diffrent connections
#color/size
set.seed(555)
id<-factor(sample(1:edge_type,net_size,replace = TRUE))
id2<-factor(sample(1:10,nodes,replace = TRUE))
edge.list<-data.frame(source=sample(1:nodes,net_size,replace=TRUE),
target=sample(1:nodes,net_size,replace=TRUE),
color=rainbow(edge_type)[id],
size=sample(seq(1,10,length.out=10),edge_type,replace=TRUE)[id],
names=letters[id],stringsAsFactors = FALSE)
node.data<-data.frame(color=sample(rainbow(10),nodes,replace=TRUE)[id2],
size=sample(seq(5,15,length.out=10),nodes,replace=TRUE)[id2],
names=sample(LETTERS[1:5],nodes,replace=TRUE)[id2],stringsAsFactors = FALSE)</code></pre>
</div>
<div id="edge-list-describing-network-connections" class="section level2">
<h2><code>Edge List</code> describing network connections</h2>
<pre class="r"><code>head(edge.list)</code></pre>
<pre><code>## source target color size names
## 1 4 5 #FF0000FF 8 a
## 2 1 3 #00FFFFFF 5 b
## 3 3 7 #00FFFFFF 5 b
## 4 3 3 #00FFFFFF 5 b
## 5 2 3 #00FFFFFF 5 b
## 6 6 3 #FF0000FF 8 a</code></pre>
</div>
<div id="node-attributes-describing-variables" class="section level2">
<h2><code>Node Attributes</code> describing variables</h2>
<pre class="r"><code>head(node.data)</code></pre>
</div>
<div id="create-2d-network" class="section level2">
<h2>Create 2D network</h2>
<pre class="r"><code>library(networkly)
library(plotly)
layout<-"fruchtermanreingold" #see networkly::get_network for 2D and 3D options
#net params
type<-"2d"
color<-'color'
size<-'size'
name<-'names'
#create network objects
obj<-get_network(edge.list,type=type,layout=layout)
net<-c(get_edges(obj,color=color,width=size,name=name,type=type,hoverinfo="none",showlegend=FALSE),get_nodes(obj,node.data,color=color,size=size,name=name,type=type,hoverinfo="name",showlegend=FALSE))
#add legend
legend<-format_legend(obj,node.data=node.data)
net<-c(net,c(get_edges(legend,color=color,width=size,name=name,type=type,hoverinfo="none",showlegend=TRUE),get_nodes(legend,node.data=legend$node.data,color=color,size=size,name=name,type=type,hoverinfo="name",showlegend=TRUE)))
net<-shiny_ly(net) # works in or out of shiny
#add layout options
layout(net,
xaxis = list(title = "", showgrid = FALSE, showticklabels = FALSE, zeroline = FALSE, hoverformat = '.2f'),
yaxis = list(title = "", showgrid = FALSE, showticklabels = FALSE, zeroline = FALSE, hoverformat = '.2f'))</code></pre>
<p><img src="inst/www/img/2dnetwork.png" /></p>
<div id="see-live-graph." class="section level3">
<h3><a href="http://dgrapov.github.io/networkly/">See live graph</a>.</h3>
</div>
</div>
<div id="create-3d-network" class="section level2">
<h2>Create 3D network</h2>
<pre class="r"><code>#net params
type<-"3d"
#create network objects
obj<-get_network(edge.list,type=type,layout=layout)
net<-c(get_edges(obj,color=color,width=size,name=name,type=type,hoverinfo="none",showlegend=FALSE),get_nodes(obj,node.data,color=color,size=size,name=name,type=type,hoverinfo="name",showlegend=FALSE))
#add legend
legend<-format_legend(obj,node.data=node.data)
net<-c(net,c(get_edges(legend,color=color,width=size,name=name,type=type,hoverinfo="none",showlegend=TRUE),get_nodes(legend,node.data=legend$node.data,color=color,size=size,name=name,type=type,hoverinfo="name",showlegend=TRUE)))
net<-shiny_ly(net)
#add layout options
layout(net,
scene = list(showlegend=TRUE,
yaxis=list(showgrid=FALSE,showticklabels=FALSE,zeroline=FALSE,title=""),
xaxis=list(showgrid=FALSE,showticklabels=FALSE,zeroline=FALSE,title=""),
zaxis=list(showgrid=FALSE,showticklabels=FALSE,zeroline=FALSE,title="")))</code></pre>
<p><img src="inst/www/img/3dnetwork.png" /></p>
<div id="see-live-graph.-1" class="section level3">
<h3><a href="http://dgrapov.github.io/networkly/">See live graph</a>.</h3>
</div>
</div>
<div id="shiny" class="section level2">
<h2>Shiny</h2>
</div>
<div id="ui.r" class="section level2">
<h2><code>ui.R</code></h2>
<pre class="r"><code>shinyUI(bootstrapPage(
plotlyOutput("network")
))</code></pre>
</div>
<div id="server.r" class="section level2">
<h2><code>server.R</code></h2>
<pre class="r"><code>shinyServer(function(session,input, output) {
output$network<-renderPlotly({
#network creation script goes here
#see above for how to create 2d or 3d networks
shiny_ly(net)
})
})</code></pre>
</div>
<div id="run-demo-app-or-try-here" class="section level2">
<h2>Run Demo App</h2>
<pre class="r"><code>networklyShiny()</code></pre>
</div>
<div id="limitations" class="section level2">
<h2>Limitations</h2>
<div id="to-allow-edge-widths-in-2d-and-3d-networks-and-to-properly-render-edge-paths-in-3d-networks-each-edge-element-is-an-independent-list-item.-the-shown-edge-and-node-legends-are-place-holders-which-do-not-correctly-show-or-hide-components.-this-can-be-changed-during-the-network-creation-procces-by-using-showlegendtrue-and-not-creating-a-place-holder-legend-as-shown-below.-for-2d-networks-edge-segments-can-be-renderd-from-a-vector-with-intermittent-nas-e.g.-xyz-source1-target1-na-source2-target2-this-currently-does-not-work-for-3d-networks.-basic-2d-networks-can-instead-be-created-from-ggplot-networks-using-plotlyggplotly." class="section level4">
<h4>To allow edge widths in 2D and 3D networks and to properly render edge paths in 3D networks each edge element is an independent list item. The shown edge and node legends are place holders which do not correctly show or hide components. This can be changed during the network creation procces by using <code>showlegend=TRUE</code> and not creating a place holder legend as shown below. For 2D networks edge segments can be renderd from a vector with intermittent NAs e.g. <code>x/y/z = source1 target1 NA source2 target2</code> this currently does not work for 3D networks. Basic 2D networks can instead be created from ggplot networks using <code>plotly::ggplotly</code>.</h4>
<pre class="r"><code>net<-c(get_edges(obj,color=color,width=size,name=name,type=type,hoverinfo="none",showlegend=TRUE),get_nodes(obj,node.data,color=color,size=size,name=name,type=type,hoverinfo="name",showlegend=TRUE))
shiny_ly(net)</code></pre>
</div>
</div>
<div id="about" class="section level2">
<h2>About</h2>
<div id="updated-2016-02-28" class="section level3">
<h3>updated 2016-02-28</h3>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
$(document).ready(function () {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>