8

Use case: I am using the riverplot package to plot sankey charts. I need to adjust the text size of the nodes labels in the plot. The default size is too big in my case.

Problem, what I tried already: Unfortunately the package does not work with a cex argument. The developer of the package did not provide guidance to me. r Reproduceable example:

library(riverplot)

plot(riverplot.example())

Generates:

enter image description here

Question:

How can I adjust the nodes labels (A, B, ...) to a smaller or larger size than default?

www
  • 38,575
  • 12
  • 48
  • 84
user2030503
  • 3,064
  • 2
  • 36
  • 53

2 Answers2

4

The package itself doesn't provide any means of setting the text size. (You can see that, if you care, by drilling down through riverplot:::plot.riverplot() to riverplot() to riverplot:::draw.nodes(); the labels are drawn by the last couple of lines of that final function, which just (implicitly) uses the global value of cex et al.)

If you're just wanting to uniformly magnify or reduce the size of node labels, though, there is a relatively easy fix. You can just temporarily reset the global value of cex, construct the plot, and then reset cex to its original value:

library(riverplot)

op <- par(cex=0.8)
plot(riverplot.example())
par(op)

enter image description here

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
3

You can apply a custom style to a river plot by building on the base default style and avoiding temporarily changing environment settings as in the accepted answer (which is a few years old, so things may have changed with riverplot since then).

To create a custom style with a custom font size:

# create a custom style by first copying from the default style
custom.style <- riverplot::default.style()

# change the font size
custom.style$textcex <- 0.8

Now just apply your custom style when rendering your plot:

plot(my.river.plot, default_style=custom.style)