riverplot: Create a Sankey plot

Description Usage Arguments Details Value Known problems See Also Examples

View source: R/riverplot.R

Description

Create a Sankey plot

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## S3 method for class 'riverplot'
plot(x, ...)

riverplot(
  x,
  direction = "lr",
  lty = 0,
  default_style = NULL,
  gravity = "top",
  node_margin = 0.1,
  nodewidth = 1.5,
  plot_area = c(1, 0.5),
  nsteps = 50,
  disentangle = TRUE,
  add_mid_points = TRUE,
  yscale = "auto",
  add = FALSE,
  usr = NULL,
  adjust.usr = FALSE,
  rescale = TRUE,
  fix.pdf = FALSE,
  bty = "n",
  ...
)

Arguments

x

An object of class riverplot

...

any further parameters passed to riverplot() are appended to the default style

direction

"lr" (left to right) or "rl" (right to left)

lty

Line style to use

default_style

default graphical style

gravity

how the nodes are placed vertically. No effect if node vertical positions are specified via node_ypos member

node_margin

how much vertical space should be kept between the nodes

nodewidth

width of the node (relative to font size)

plot_area

fraction of vertical and horizontal space to be used as main plot area If it is a numeric vector of two numbers, the first one is horizontal space, the second vertical.

nsteps

number of interpolating steps in drawing the segments

disentangle

try to disentangle connections between the nodes. If FALSE, the vertical ordering of the connections is the same as in the x$edges data frame.

add_mid_points

attempt to get a smoother plot by adding additional nodes. Set this parameter to FALSE if you are setting node vertical position manually. If add_mid_points is equal to TRUE (the default), then the mid points are added only if node_ypos is empty.

yscale

scale the edge width values by multiplying with this factor. If yscale is equal to "auto", scaling is done automatically such that the vertical size of the largest node is approximately 15 If no node_ypos is specified in the riverplot object, no scaling is done. If yscale is equal to 1, no scaling is done. This parameter only influences the plot if the y positions of the nodes are provided in x$nodes.

add

If TRUE, do not call plot.new(), but add to the existing plot.

usr

coordinates at which to draw the plot in form (x0, x1, y0, y1). If NULL, par("usr") will be used instead.

adjust.usr

If TRUE, the par("usr") will be modified to suit the x and y coordinates of the riverplot nodes (whether the coordinates were given in the nodes, or calculated by the function). In combination with providing x and y coordinates, this allows a true representation of a riverplot object. Necessary if you plan to plot additional, external data. If TRUE, then rescale is set to FALSE. See minard data set and example for details.

rescale

if TRUE, then the plot will be fit into the given user coordinates range (set by the usr parameter, for example, or the whole plot region). If FALSE, the x and y positions of the nodes will be treated as user coordinates and used to directly plot on the device.

fix.pdf

Try to fix PDF output if it looks broken (with thin white lines). Don't use this option if you are using transparent colors.

bty

box type to draw around the plot; see bty in documentation for par for details.

Details

This functions create a Sankey plot given a riverplot object (plot is just a wrapper for the riverplot function. The object to be drawn is a list specifying the plot; see the makeRiver function for exact specifications and the riverplot.example to see how it can be created. 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.

Style information which is missing from the riverplot object x (for example, if the node style is not specified for each node in the object) is taken from the default.style parameter. See functions default.style() and updateRiverplotStyle() to learn how to create and modify the styles.

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. These functions here are for the convenience of checking that

The nodes are drawn from bottom to top in the order they are found in the riverplot object. There is no clever algorithm for placing the nodes minimizing the number of crossing edges yet; you need to manipulate the object directly to achieve the desired effect.

Value

riverplot returns a riverplot object, a graph which you can plot again with riverplot(), but which additionally contains information on node position and size in the $nodes member.

Known problems

There is a problem with transparency and PDFs. In short, if you try to save your riverplot graphics as PDF, you will observe thin, white vertical lines everywhere on the curves. The reasons for that are unclear, but have something to do with PDF rendering (if you generate EPS, the output looks good).

There is a kind of fix to that: use the fix.pdf=TRUE option. Unfortunately, this solution does not work if you use transparent colors (you will have a different kind of vertical lines). Unfortunately, I don't have a solution for that problem yet.

See Also

default.style updateRiverplotStyle minard

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- riverplot.example()
plot(x)
plot(x, srt=90, lty=1)

# add graphics at nodes
foo <- plot(x, srt=90, lty=1)
points(foo$nodes$x, foo$nodes$y, pch=19, cex=2)

# redraw the same graph using positions from foo object
plot(foo, yscale=1)

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