简体   繁体   中英

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. 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. I've tried creating blank node labels, but both sides of the plot get removed when I've done this.

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. I fear this might be impossible with how the Riverplot package is set up, but any help would be appreciated.

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. 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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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