I'm trying to make a Sankey diagram using the riverplot package, and was wondering if it's possible to add a title and axis labels to the plot. To keep it simple I'll use one of the sample riverplots from the package:
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 , srt = 0)
I've tried using labs() and get the following error message: 'non-numeric argument to binary operator' (which wasn't unexpected), but since the package itself doesn't seem to have arguments for the title or axis labels, I'm at a bit of a loss. Any help is much appreciated!
Try creating an empty plot first with your labels and then riverplot::riverplot
has an argument add
. Set that to True
to plot on your empty initial plot. You can customize the initial plot as you see fit with the base facility.
# empty plot
plot(0,
type = "n",
xlab = "x-axis",
ylab = "y-axis",
frame.plot = F,
xaxt = "n",
yaxt = "n",
main = "TITLE")
riverplot::riverplot(r,
add = T) # add to empty plot