-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.Rmd
503 lines (470 loc) · 14.2 KB
/
index.Rmd
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
[![Travis-CI Build Status](https://travis-ci.org/JohnCoene/sigmajs.svg?branch=master)](https://travis-ci.org/JohnCoene/sigmajs) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/JohnCoene/sigmajs?branch=master&svg=true)](https://ci.appveyor.com/project/JohnCoene/sigmajs) [![bitbucket](https://img.shields.io/bitbucket/pipelines/JohnCoene/sigmajs.svg)](https://bitbucket.org/JohnCoene/sigmajs) [![CircleCI](https://img.shields.io/circleci/project/github/JohnCoene/sigmajs.svg)](https://github.com/JohnCoene/sigmajs) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) [![CRAN status](https://www.r-pkg.org/badges/version/sigmajs)](https://cran.r-project.org/package=sigmajs) [![Coverage status](https://codecov.io/gh/JohnCoene/sigmajs/branch/master/graph/badge.svg)](https://codecov.io/github/JohnCoene/sigmajs?branch=master) [![Coverage status](https://coveralls.io/repos/github/JohnCoene/sigmajs/badge.svg)](https://coveralls.io/r/JohnCoene/sigmajs?branch=master) [![DOI](http://joss.theoj.org/papers/10.21105/joss.00814/status.svg)](https://doi.org/10.21105/joss.00814) [![twinetverse](https://img.shields.io/badge/twinetverse-0.0.2-yellow.svg)](http://twinetverse.john-coene.com/)
[![CRAN log](http://cranlogs.r-pkg.org/badges/grand-total/sigmajs)](http://cranlogs.r-pkg.org/badges/sigmajs)
```{r, include=FALSE}
library(htmltools)
library(sigmajs)
library(dplyr)
```
```{r, message = FALSE, eval=TRUE, echo = FALSE, warning = FALSE}
# ----------------------------- GET STARTED
nodes_demo <- sg_make_nodes()
edges_demo <- sg_make_edges(nodes_demo, 17)
nodes_demo$size <- 1
get_started <- sigmajs(height = 150) %>%
sg_nodes(nodes_demo, id, color, size) %>%
sg_edges(edges_demo, id, source, target) %>%
sg_settings(defaultNodeColor = "#98D3A5",
mouseEnabled = FALSE,
touchEnabled = FALSE,
minNodeSize = 3,
maxNodeSize = 3) %>%
sg_layout()
# ----------------------------- DYNAMIC
edges_demo$delay <- runif(nrow(edges_demo), 2000, 10000) # between .5 and 2 seconds
src <- edges_demo[, c("source", "delay")]
tgt <- edges_demo[, c("target", "delay")]
names(tgt) <- c("source", "delay")
nodes <- src %>%
bind_rows(tgt) %>%
group_by(source) %>%
summarise(
delay = min(delay) - 10,
size = n()
) %>%
ungroup() %>%
mutate(
color = sample(
c("#B1E2A3", "#98D3A5", "#328983", "#1C5C70", "#24C96B"),
n(), replace = TRUE)) %>%
select(id = source, delay, size, color)
last_edge <- max(nodes$delay) + 100
dyn <- sigmajs(height = 150) %>%
sg_force_start() %>%
sg_add_nodes(nodes, delay, id, size, color, cumsum = FALSE) %>%
sg_add_edges(edges_demo, delay, id, source, target, refresh = TRUE, cumsum = FALSE) %>% # read delay documentation
sg_force_stop(last_edge) %>%
sg_settings(mouseEnabled = FALSE,
touchEnabled = FALSE,
minNodeSize = 1,
maxNodeSize = 4)
# ----------------------------- ANIMATE
n <- nrow(nodes_demo)
layout <- sg_get_layout(nodes_demo, edges_demo)
nodes_demo$to_x <- layout$x
nodes_demo$to_y <- layout$y
nodes_demo$to_size <- runif(n, 5, 10)
nodes_demo$color <- sample(c("#ffe66d", "#e85d75"), n, replace = TRUE)
nodes_demo$to_color <- sample(c("#B1E2A3", "#98D3A5", "#328983", "#1C5C70",
"#24C96B"), n, replace = TRUE)
animate <- sigmajs(height = 150) %>%
sg_nodes(nodes_demo, id, label, size, color, to_x, to_y, to_size, to_color) %>%
sg_edges(edges_demo, id, source, target) %>%
sg_animate(mapping = list(x = "to_x", y = "to_y", size = "to_size", color = "to_color"),
delay = 500) %>%
sg_settings(animationsTime = 10000,
minNodeSize = 1,
maxNodeSize = 5,
mouseEnabled = FALSE,
touchEnabled = FALSE)
br()
div(
class = "row",
div(
class = "col-md-8",
h1(
"sigmajs",
a(
class = "github-button",
href = "https://github.com/JohnCoene/sigmajs",
`data-show-count` = "true",
`aria-label` = "Star JohnCoene/sigmajs on GitHub",
"Star"
)
),
a("sigma.js", href = "http://sigmajs.org/", target = "_blank"),
" for R. A powerful, full-featured R package for interactive graph visualisation.",
br(),
br(),
tags$button(
role = "button",
"How to ",
class = "btn btn-warning",
`data-toggle` = "collapse",
href = "#collapseExample",
`aria-expanded` = "false",
`aria-controls` = "collapseExample",
tags$i(
class = "fa fa-rocket"
)
)
),
div(
class = "col-md-4",
br(),
img(
src = "man/figures/logo.png",
class = "img-responsive",
style = "margin:0 auto;max-height:200px;"
)
)
)
br()
br()
div(
class = "collapse",
id = "collapseExample",
div(
class = "well",
"Start with the 1)", a("get started guide", href = "articles/get_started.html"),
"to get up to speed, then move on to 2)",
a("layouts", href = "articles/layout.html"), "then to 3)",
a("buttons", href = "articles/buttons.html"), "and finally 4)",
a("dynamic graphs", href = "articles/dynamic.html"),
"and you should be at ease with the core functionalities."
)
)
h2("Features")
div(
class = "row",
div(
class = "col-md-4",
div(
class = "thumbnail",
div(
class = "caption",
h3("Customisation"),
get_started,
p("Easily and neatly layout and cluster nodes on your", code("sigmajs"), "graphs."), br(),
p(
a(
href = "articles/layout.html",
class = "btn btn-primary",
tags$i(class = "fa fa-share-alt"),
"Layout"
),
a(
href = "articles/cluster.html",
class = "btn btn-success",
tags$i(class = "fa fa-cubes"),
"Cluster"
)
)
)
)
),
div(
class = "col-md-4",
div(
class = "thumbnail",
div(
class = "caption",
h3("Dynamism"),
dyn,
p("Learn how to make a temporal graph in static R markdown documents."),
p(
a(
href = "articles/dynamic.html",
class = "btn btn-primary",
tags$i(class = "fa fa-spinner fa-pulse fa-fw"),
"Dynamic"
),
a(
href = "articles/buttons.html",
class = "btn btn-success",
tags$i(class = "fa fa-gavel"),
"Buttons"
)
)
)
)
),
div(
class = "col-md-4",
div(
class = "thumbnail",
div(
class = "caption",
h3("Animations"),
animate,
p("Animate the color, size, and x/y coordinates of the nodes on the canvas."),
p(
a(
href = "articles/animate.html",
class = "btn btn-primary",
tags$i(class = "fa fa-cogs"),
"Animate"
)
)
)
)
)
)
div(
tags$ul(
class = "nav nav-tabs",
role = "tablist",
tags$li(
role = "presentation",
class = "active",
tags$a(
href = "#shiny",
`aria-controls` = "shiny",
role = "tab",
`data-toggle` = "tab",
tags$i(class = "fa fa-desktop"),
"Shiny"
)
),
tags$li(
role = "presentation",
tags$a(
href = "#dynamism",
`aria-controls` = "dynamism",
role = "tab",
`data-toggle` = "tab",
tags$i(class = "fa fa-exchange"),
"Crosstalk"
)
),
tags$li(
role = "presentation",
tags$a(
href = "#formats",
`aria-controls` = "formats",
role = "tab",
`data-toggle` = "tab",
tags$i(class = "fa fa-file-code-o"),
"Formats"
)
)
),
div(
class = "tab-content",
div(
class = "tabpanel",
class = "tab-pane fade active in",
id = "shiny",
div(
class = "row",
div(
class = "col-md-8",
p(
code("sigmajs"), "plays hand-in-hand with Shiny, it lets you:",
tags$ul(
tags$li("Catch how users interact with your graphs."),
tags$li("Easily apply filters."),
tags$li("Trigger events.")
)
)
),
div(
class = "col-md-4",
br(),
p(
a(
href = "articles/shiny.html",
class = "btn btn-primary",
tags$i(class = "fa fa-graduation-cap"),
"Guide"
),
a(
href = "http://shiny.john-coene.com/sigmajs/",
target = "_blank",
class = "btn btn-success",
tags$i(class = "fa fa-desktop"),
"Demo"
)
)
)
)
),
div(
class = "tabpanel",
class = "tab-pane fade",
id = "dynamism",
div(
class = "row",
div(
class = "col-md-10",
p("Have", code("sigmajs"), "play hand-in-hand with other",
a("htmlwidgets,", href = "https://rstudio.github.io/crosstalk/widgets.html", target = "_blank"),
" such as", a("leaflet,", href = "https://rstudio.github.io/leaflet/", target = "_blank"), "or",
a("DT", href = "https://rstudio.github.io/DT/", target = "_blank"),
" to highlight nodes and neighbours on click."
)
),
div(
class = "col-md-2",
p(
a(
href = "articles/talkcross.html",
class = "btn btn-primary",
tags$i(class = "fa fa-exchange"),
"Crosstalk"
)
)
)
)
),
div(
class = "tabpanel",
class = "tab-pane fade",
id = "formats",
div(
class = "row",
div(
class = "col-md-8",
p("Build", code("sigmajs"), "graphs from igraph objects or GEXF files in a single function call.")
),
div(
class = "col-md-4",
p(
a(
href = "articles/formats.html#igraph",
class = "btn btn-primary",
tags$i(class = "fa fa-share-alt"),
"igraph"
),
a(
href = "articles/formats.html#gexf",
target = "_blank",
class = "btn btn-success",
tags$i(class = "fa fa-file-code-o"),
"GEXF"
)
)
)
)
)
)
)
```
## Install
Install the stable version from CRAN.
```{r, eval = FALSE}
install.packages("sigmajs")
```
or the development version Github or Bitbucket.
```{r, eval = FALSE}
# install.packages("remotes")
remotes::install_github("JohnCoene/sigmajs") # github
remotes::install_bitbucket("JohnCoene/sigmajs") # bitbucket
```
## Example
*Note that the graphs do not work in the RStudio viewer, and thus open in your default browser.*
```{r, eval=TRUE, warning = FALSE}
library(sigmajs)
# generate data
nodes <- sg_make_nodes(25) # 20 nodes
edges <- sg_make_edges(nodes, 50) # 50 edges
sigmajs() %>% # initialise
sg_nodes(nodes, id, label, size) %>% # add nodes
sg_edges(edges, id, source, target) %>% # add edges
sg_layout() %>% # layout
sg_cluster() %>% # cluster
sg_drag_nodes() %>% # allows user to drag nodes
sg_neighbours() # show node neighbours on node click
```
```{r, echo=FALSE, warning = FALSE}
br()
div(
class = "panel panel-default",
div(
class = "panel-body",
div(
class = "row",
div(
class = "col-md-10",
"sigmajs is part of the", "twinetverse,",
"a set of packages for Twitter network analysis and visualisation: it'll",
tags$strong("1) get you started with network data"), "and",
strong("2) walk you through from basic use cases to advanced functions.")
),
div(
class = "col-md-2",
tags$button(
type = "button",
"Twinetverse ",
`data-toggle` = "modal",
`data-target` = "#twinetverse",
class = "btn btn-info"
)
)
)
)
)
div(
class = "modal fade",
id = "twinetverse",
tabindex = "-1",
role = "dialog",
`aria-labelledby` = "myModalLabel",
div(
class = "modal-dialog",
role = "document",
div(
class = "modal-content",
div(
class = "modal-header",
tags$button(
type = "button",
class = "close",
`data-dismiss` = "modal",
`aria-label` = "Close",
tags$span(
`aria-hidden` = "true",
tags$i(class = "fa fa-times")
)
),
tags$h4(class = "modal-title", id = "myModalLabel", "Twinetverse")
),
div(
class = "modal-body",
img(
src = "http://twinetverse.john-coene.com/reference/figures/logo.png",
style = "max-height:150px;",
align = "right"
),
"The", a("twinetverse", href = "http://twinetverse.john-coene.com/", target = "_blank"), "is a set of packages,",
tags$i("including sigmajs,"), "to visualise Twitter interactions, it includes everything you need to:",
br(),
br(),
tags$ol(
tags$li(
"Collect data"
),
tags$li(
"Build, and"
),
tags$li(
"Visualise graphs"
)
),
br(),
"The", a("twinetverse", href = "http://twinetverse.john-coene.com/", target = "_blank"), "comes with an in-depth guide:",
"a 12 chapter-long book filled with examples.", "It is highly recommended if you want to fully grasp the intricacies of sigmajs.",
"The book will also get you setup and running with",
strong("real-world, easy to understand"), "network data if you are unfamiliar with it."
),
div(
class = "modal-footer",
tags$a(
href = "http://twinetverse.john-coene.com/",
target = "_blank",
class = "btn btn-default",
tags$i(class = "fa fa-desktop"),
" Website"
),
tags$a(
href = "http://twinetbook.john-coene.com/",
target = "_blank",
class = "btn btn-primary",
tags$i(class = "fa fa-book"),
" Book"
)
)
)
)
)
```
<script async defer src="https://buttons.github.io/buttons.js"></script>