makeRiver: Create a new riverplot object

Description Usage Arguments Details Value Structure of the riverplot objects Generating riverplot objects Riverplot styles Author(s) Examples

View source: R/importexport.R

Description

Create a new riverplot object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
makeRiver(
  nodes,
  edges,
  node_labels = NULL,
  node_xpos = NULL,
  node_ypos = NULL,
  styles = NULL,
  node_styles = NULL,
  edge_styles = NULL,
  default_style = NULL
)

Arguments

nodes

Data frame with node ID's, positions and optionally other information

edges

A named list or a data frame specifying the edges between the nodes.

node_labels

A named character vector of labels for the nodes

node_xpos

A named vector of numeric values specifying the horizontal positions on the plot.

node_ypos

A named vector of numeric values specifying the vertical positions on the plot.

styles

A named list specifying the styles for the nodes and edges

node_styles

Deprecated

edge_styles

Deprecated

default_style

list containing style information which is applied to every node and every edge

Details

Functions to create a new object of the riverplot class from the provided data.

makeRiver creates a plot from an object which specifies the graph directly, i.e. all nodes, their horizontal positions on the plot, provided styles etc. See sections below for detailed explanations.

Value

A riverplot object which can directly be plotted.

Structure of the riverplot objects

A riverplot object is a list with the following entries:

nodes

A data frame specifying the nodes, containing at least the columns "ID" and "x" (horizontal position of the node). Optionally, it can also contain columns "labels" (the labels to display) and "y" (vertical position of the node on the plot)

edges

A data frame specifying the edges and graph topology, containing at least the columns "ID", "N1", "N2" and "Value", specifying, respectively, the ID of the edge, the parent node, the child node, and the size of the edge.

styles

A named list of styles. Names of this list are the node or edge IDs. Values are styles specifying the style of the given node or edge (see below).

Whether or not the list used to plot is exactly of class riverplot-class does not matter as long as it has the correct contents. The makeRiver function is here are for the convenience of checking that this is the case and converting information in different formats.

Generating riverplot objects

To generate and fool-proof riverplot objects, you can use the makeRiver function. This functions allows a number of ways of specifying the node and edge information.

Nodes can be specified as a character vector (simply listing the nodes) or as a data frame.

Edges / graph topology can be specified in one of two objects: either a named list, or a data frame:

Riverplot styles

Styles are lists containing attributes (such as "col" for color or "nodestyle") and values. There is no real difference between node and edge styles, except that some attributes only apply to nodes or edges. See riverplot-styles for more information on style attributes.

When makeRiver generates the riverplot object, it combines style information from the following sources in the following order:

Author(s)

January Weiner

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
nodes <- c( LETTERS[1:3] )
edges <- list( A= list( C= 10 ), B= list( C= 10 ) )
r <- makeRiver( nodes, edges, node_xpos= c( 1,1,2 ),
  node_labels= c( A= "Node A", B= "Node B", C= "Node C" ),
  node_styles= list( A= list( col= "yellow" )) )
plot( r )

# equivalent form:
nodes <- data.frame( ID= LETTERS[1:3],
               x= c( 1, 1, 2 ),
               col= c( "yellow", NA, NA ),
               labels= c( "Node A", "Node B", "Node C" ),
               stringsAsFactors= FALSE )
r <- makeRiver( nodes, edges )
plot( r )
# all nodes but "A" will be red:
r <- makeRiver( nodes, edges, default_style= list( col="red" ) )
plot( r )
# overwrite the node information from "nodes":
r <- makeRiver( nodes, edges, node_styles= list( A=list( col="red" ) ) )
plot( r )

Example output

--------------
Default style:
-----------
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"
--------------
[1] "checking edges"
[1] "adding mid points"
Updated styles:
$A
$col
[1] "yellow"

$nodestyle
[1] "regular"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$B
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$C
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$`A->C`
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$`B->C`
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

--------------
[1] "calculating sizes"
$lefts
 A  B  C 
 0  0 20 

$rights
 A  B  C 
10 10  0 

$sizey
 A  B  C 
10 10 20 

[1] "calculating positions"
[1] 2
  ID x labels
A  A 1 Node A
B  B 1 Node B
C  C 2 Node C
[1] "done"
[1] "drawing edges"
[1] "drawing nodes"
--------------
Default style:
-----------
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"
--------------
[1] "checking edges"
[1] "adding mid points"
Updated styles:
$A
$col
       A 
"yellow" 

$nodestyle
[1] "regular"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$B
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$C
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$`A->C`
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$`B->C`
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

--------------
[1] "calculating sizes"
$lefts
 A  B  C 
 0  0 20 

$rights
 A  B  C 
10 10  0 

$sizey
 A  B  C 
10 10 20 

[1] "calculating positions"
[1] 2
  ID x    col labels
A  A 1 yellow Node A
B  B 1   <NA> Node B
C  C 2   <NA> Node C
[1] "done"
[1] "drawing edges"
[1] "drawing nodes"
--------------
Default style:
-----------
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"
--------------
[1] "checking edges"
[1] "adding mid points"
Updated styles:
$A
$col
       A 
"yellow" 

$nodestyle
[1] "regular"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$B
$col
[1] "red"

$nodestyle
[1] "regular"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle" "riverplotStyle"

$C
$col
[1] "red"

$nodestyle
[1] "regular"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle" "riverplotStyle"

$`A->C`
$col
[1] "red"

$nodestyle
[1] "regular"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle" "riverplotStyle"

$`B->C`
$col
[1] "red"

$nodestyle
[1] "regular"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle" "riverplotStyle"

--------------
[1] "calculating sizes"
$lefts
 A  B  C 
 0  0 20 

$rights
 A  B  C 
10 10  0 

$sizey
 A  B  C 
10 10 20 

[1] "calculating positions"
[1] 2
  ID x    col labels
A  A 1 yellow Node A
B  B 1   <NA> Node B
C  C 2   <NA> Node C
[1] "done"
[1] "drawing edges"
[1] "drawing nodes"
--------------
Default style:
-----------
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"
--------------
[1] "checking edges"
[1] "adding mid points"
Updated styles:
$A
$col
[1] "red"

$nodestyle
[1] "regular"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$B
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$C
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$`A->C`
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

$`B->C`
$nodestyle
[1] "regular"

$col
[1] "grey"

$srt
[1] "90"

$lty
[1] 1

$textcol
[1] "black"

$textcex
[1] 1

$edgecol
[1] "gradient"

$edgestyle
[1] "sin"

attr(,"class")
[1] "list"           "riverplotStyle"

--------------
[1] "calculating sizes"
$lefts
 A  B  C 
 0  0 20 

$rights
 A  B  C 
10 10  0 

$sizey
 A  B  C 
10 10 20 

[1] "calculating positions"
[1] 2
  ID x    col labels
A  A 1 yellow Node A
B  B 1   <NA> Node B
C  C 2   <NA> Node C
[1] "done"
[1] "drawing edges"
[1] "drawing nodes"

riverplot documentation built on Jan. 22, 2021, 5:09 p.m.