2

I am using the riverplot package in R. I am able to make a Sankey diagram. I would like to be able to add a vertical label (preferably on the bottom). I found one example that appears to do this: http://www.statsmapsnpix.com/2016/08/research-with-qgis-r-and-speaking-to.html (I am referring to Figure 20, near the top - labels like 2004 and 2015 are what I am trying to figure out how to create).

How can I do this myself?

Here is a MWE, taken directly from the package documentation at https://cran.r-project.org/web/packages/riverplot/riverplot.pdf

library(riverplot)
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 )

Here, I would like to have a label under Node A and Node B called Left and another label under Node C called Right.

www
  • 38,575
  • 12
  • 48
  • 84
bill999
  • 2,147
  • 8
  • 51
  • 103

1 Answers1

2

Here's one way to do it:

library(riverplot)
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" )) )
(coords <- plot(r))
#          A   B   C
# x        1   1   2
# top    -22 -10 -20
# center -17  -5 -10
# bottom -12   0   0
text(
  x = range(coords["x",]),
  y = min(coords["top",]),
  labels = c("left", "right"),
  pos = 1, offset = 0, font = 2
)

enter image description here

lukeA
  • 53,097
  • 5
  • 97
  • 100