bipartite_D3: Generate interactive bipartite networks

Description Usage Arguments Details Value Examples

View source: R/bipartite_D3.r

Description

Plots one or more interactive bipartite graphs. Data can be supplied either in bipartite package format or as a data frame and generates an html widget. There are range of display options, see vignette for examples.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
bipartite_D3(data, filename = "bipartiteD3Script",
  PrimaryLab = "Primary", SecondaryLab = "Secondary",
  SiteNames = NULL, colouroption = c("monochrome", "brewer",
  "manual")[1], HighlightLab = "Unlinked", HighlightCol = "#3366CC",
  monoChromeCol = "rgb(56,43,61)", ColourBy = c(1, 2)[2],
  BrewerPalette = "Accent", NamedColourVector, MainFigSize = NULL,
  SortPrimary = NULL, SortSecondary = NULL, mp = c(1, 1),
  MinWidth = 10, Pad = 1, IndivFigSize = c(200, 400), BarSize = 35,
  Orientation = c("vertical", "horizontal")[1],
  EdgeMode = c("straight", "smooth")[2], BoxLabPos = NULL,
  IncludePerc = TRUE, PercPos = NULL, CSS_Output_Supress = FALSE,
  PRINT = FALSE)

Arguments

data

Food web or webs to be plotted. Can be either in data.frame format (Sp1,Sp2, Site1, Site2 etc) or bipartite style matrix, list of matrices or array.

filename

Character string to name the .js and .css files. Do not include a file extension.

PrimaryLab

Character string to label left (lower) half of graph (e.g. 'plant' or 'host').

SecondaryLab

Character string to label right (upper) half of graph (e.g. 'pollinator' or 'parasitoid').

SiteNames

Character vector giving name or names of site or sites. Used as a title for facets.

colouroption

Either 'monochrome', 'brewer' or 'manual'.

HighlightLab

Name of interactor species to highlight. (Text must match).

HighlightCol

Colour to highlight species. Can be any format read by html, eg simple names: 'PINK', hexcode: '#FFC0CB' or rgb: 'rgb(255,192,203)'

monoChromeCol

If using monochrome option, what colour to use. Can be any format read by html, eg simple names 'PINK', hexcode '#FFC0CB' or rgb 'rgb(255,192,203)'

ColourBy

Which set of interactors to colour by. 1= primary, 2= secondary

BrewerPalette

RColorBrewer palette to use, e.g. 'Set3'. Be sure to select one with enough available colours (it will warn)

NamedColourVector

Named vector of colours for manual colour assignment. Can be any format read by html, eg simple names 'PINK', hexcode '#FFC0CB' or rgb 'rgb(255,192,203)'

MainFigSize

c(width, height). Size of html container for the whole figure

SortPrimary

Vector of order of species to arrange primary level. Default is alphabetical

SortSecondary

Vector of order of species to arrange secondary level. Default is alphabetical

mp

Numeric vector c(rows, columns) for distribution of facets

MinWidth

Numeric. Minumum size to shrink unselected interactors to.

Pad

Numeric. Whitespace gap between species.

IndivFigSize

c(width, height) Size of each facet, specifically the links

BarSize

Thickness of bars representing interactors

Orientation

Either 'horizontal' or 'vertical' orientation. Note that Vertical is currently much better supported!

EdgeMode

Set to 'straight' if you want to avoid default curly lines.

BoxLabPos

c(x_primary,x_secondary) To adjust position of species labels away from graph. Default is based on maximum length of labels.

IncludePerc

Logical - whether or not to show percentage links

PercPos

c(x_p,x_s) To adjust position of percentages away from graph. Default is based on maximum length of labels.

CSS_Output_Supress

Logical - set to TRUE if you have changed the CSS file manually and don't want it overridden

PRINT

Logical - output generated JavaScript to screen?

Details

This function offers a straightforward way to generate an interactive bipartite graph. Hovering over a species will focus just on that species and its interactors, and display their relative fractions. Where multiple networks are examined simultaneously, the selection occurs in tandem.

It will try to download source code of a version of the vis JavaScript library, generate a JavaScript file (.js) and a Cascading Style Sheet (.css) and place them in the working directory. These are then used by r2d3() to create an html object.

When used in RStudio version 1.2+ this is visible in the viewer pane. If using an earlier version of Rstudio, the graph may appear as a blank space in the default RStudio viewer. In this case, you can still use knitr to create an html file and view it in a browser.

Guessing appropriate sizes for the figures can be a process of trial and error. The best values depend on the length of the labels, the number of interactions and their relative weighting. See Vignette for details. If the figure looks weirdly proportioned, the links appear to invert or one of the halves is notably longer than other other, the main figure margins are probably too small. It is often necessary to experiment a little with large or complex figures.

To include figures as a static plot for publication, there are several options. If using RStudio v1.2+, then it is possible to just export from the viewer pane. Otherwise, from an html document generated by knitr, it is often useful to 'print to pdf' within the browser. Finally is possible to extract the svg segment that relates to the figure from the html file and save it directly as an svg file, which can then be used in e.g. Inkscape.

Value

Uses r2d3() to generate an html widget object. Can be viewed either in viewer pane (RStudio V1.2+) or with knitr. See Vignette. As a side effect, saves visjs.js (the vis plotting library), filename.js and filename.css to the working directory.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Simple Bipartite Style Data Set:
testdata <- data.frame(higher = c("bee1","bee1","bee1","bee2","bee1","bee3"),
lower = c("plant1","plant2","plant1","plant2","plant3","plant4"),
webID = c("meadow","meadow","meadow","meadow","meadow","meadow"), freq=c(5,9,1,2,3,7))
SmallTestWeb <- bipartite::frame2webs(testdata,type.out="array")


bipartite_D3(SmallTestWeb, filename = 'demo1')

## For more examples see vignette

bipartiteD3 documentation built on Nov. 27, 2018, 1:05 a.m.