简体   繁体   English

R Riverplot 删除 Sankey plot 一侧的节点标签

[英]R Riverplot remove node labels on one side of Sankey plot

I'm using Riverplot to create Sankey plots and placing them in one plot to create a continuous look with three plots.我正在使用 Riverplot 创建 Sankey 图并将它们放在一个 plot 中,以创建具有三个图的连续外观。 My problem is that I only want node labels on the outmost left and right nodes, not inside.我的问题是我只想要最外面的左右节点上的节点标签,而不是里面。
I've managed to remove the labels from the middle plot with the following code to create the objects, but I was wondering if there is a way to remove only one side of the labels.我已经设法使用以下代码从中间 plot 中删除标签来创建对象,但我想知道是否有办法只删除标签的一侧。 I've tried creating blank node labels, but both sides of the plot get removed when I've done this.我已经尝试创建空白节点标签,但是当我完成此操作时,plot 的两侧都会被删除。

make_rp = function(edges) {
  nodes = data.frame(ID=unique(c(edges$N1, edges$N2)),
                     x=rep(c(1,2), each=9)) 
  
  style = sapply(nodes$ID, function(id)
    list(col=cols[gsub('(  |) ', '', id)]),
    simplify=FALSE)
  
  rp = makeRiver(nodes, edges, styles=style)
}

make_rp_inner = function(edges) {
  nodes = data.frame(ID=unique(c(edges$N1, edges$N2)),
                     x=rep(c(1,2), each=9)) 
  
  style = sapply(nodes$ID, function(id)
    list(col=cols[gsub('(   |) ', '', id)]),
    simplify=FALSE)
  
  rp = makeRiver(nodes, edges, styles=style, node_labels=c('','','','','','','','',''))
}

and this is my code for plotting:这是我的绘图代码:

par(mar=c(0,0,0,0), mfrow=c(1,3), cex=1.2)
riverplot(rp_90_00,srt=0, plot_area=c(1,.7), gravity='top',
          nodewidth=1.2, node_margin=0.2, fix.pdf=TRUE)

riverplot(rp_00_10,srt=0, plot_area=c(1,.7), gravity='top',
          nodewidth=1, node_margin=0.2, fix.pdf=TRUE)  # uses rp_innner function

riverplot(rp_10_20,srt=0, plot_area=c(1,.7), gravity='top',
          nodewidth=1.4, node_margin=0.2, fix.pdf=TRUE)

This is the plot I have currently and I want all but the labels on the outside to be removed.这是我目前拥有的 plot,我希望除去外面的所有标签。 I fear this might be impossible with how the Riverplot package is set up, but any help would be appreciated.我担心如何设置 Riverplot package 可能是不可能的,但我们将不胜感激。

I found somewhat of a solution to this problem, though it involves a lot of manual input.尽管涉及大量手动输入,但我找到了解决此问题的方法。 I ended up having to remove all the node labels.我最终不得不删除所有节点标签。 The main idea is node_labels being essentially null, but you can't define it simply as =NULL.主要思想是 node_labels 本质上是 null,但不能简单地将其定义为 =NULL。 The following code is a simplified versions of what I've done:以下代码是我所做的简化版本:

plot_n = makeRiver(nodes=nodes, edges=edges, styles=style, 
                   node_labels=c('','','','','','','','',''))

I then added labels manually to the plot.然后我手动将标签添加到 plot。

par(mfrow=c(1,3))

riverplot(plot_1)

text("LDW", x = 0.04, y = .88)
text("MDW", x = 0.04, y = .72)
text("LDL", x = 0.04, y = .615)
text("MDL", x = 0.04, y = .523)
text("LDB", x = 0.04, y = .425)
text("MDB", x = 0.04, y = .33)
text("LDA", x = 0.04, y = .235)
text("MDA", x = 0.04, y = .15)
text("HD", x = 0.03, y = .06)

riverplot(plot_2)

riverplot(plot_3)

text("LDW", x = .96, y = .915)
text("MDW", x = 0.96, y = .762)
text("LDL", x = 0.96, y = .64)
text("MDL", x = 0.96, y = .54)
text("LDB", x = 0.96, y = .44)
text("MDB", x = 0.96, y = .341)
text("LDA", x = 0.96, y = .246)
text("MDA", x = 0.96, y = .155)
text("HD", x = 0.98, y = .063)

What I noticed is different results occur in pdf versus png, jpeg, etc. formats, but tweaking is fairly easy once the general points are figured out.我注意到 pdf 与 png、jpeg 等格式的结果不同,但是一旦弄清楚了一般要点,调整就相当容易了。 I hope this can help anyone with a similar problem until a better solution gets discovered or implemented.我希望这可以帮助任何有类似问题的人,直到发现或实施更好的解决方案。 The following image is the fixed version of the one in my question.下图是我的问题中的固定版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM