簡體   English   中英

R Riverplot 刪除 Sankey plot 一側的節點標簽

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

我正在使用 Riverplot 創建 Sankey 圖並將它們放在一個 plot 中,以創建具有三個圖的連續外觀。 我的問題是我只想要最外面的左右節點上的節點標簽,而不是里面。
我已經設法使用以下代碼從中間 plot 中刪除標簽來創建對象,但我想知道是否有辦法只刪除標簽的一側。 我已經嘗試創建空白節點標簽,但是當我完成此操作時,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('','','','','','','','',''))
}

這是我的繪圖代碼:

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)

這是我目前擁有的 plot,我希望除去外面的所有標簽。 我擔心如何設置 Riverplot package 可能是不可能的,但我們將不勝感激。

盡管涉及大量手動輸入,但我找到了解決此問題的方法。 我最終不得不刪除所有節點標簽。 主要思想是 node_labels 本質上是 null,但不能簡單地將其定義為 =NULL。 以下代碼是我所做的簡化版本:

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

然后我手動將標簽添加到 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)

我注意到 pdf 與 png、jpeg 等格式的結果不同,但是一旦弄清楚了一般要點,調整就相當容易了。 我希望這可以幫助任何有類似問題的人,直到發現或實施更好的解決方案。 下圖是我的問題中的固定版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM