首页 > 解决方案 > 向河图添加标题和轴标签?

问题描述

我正在尝试使用 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 , srt = 0)

没有标题/轴标签的河图

我尝试使用 labs() 并收到以下错误消息:“二进制运算符的非数字参数”(这并不意外),但由于包本身似乎没有标题或轴标签的参数,我有点不知所措。任何帮助深表感谢!

标签: rsankey-diagramriverplot

解决方案


你需要功能title

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, srt = 0,
     main = "My Title")

title(main = "My title",
      xlab = "My label for axis X",
      ylab = "My label for axis Y")

这段代码给你

在此处输入图像描述


推荐阅读