2017-06-15 59 views
1

我在R中使用riverplot包。我能够制作Sankey图。我希望能够添加垂直标签(最好在底部)。我发现一个例子似乎这样做:http://www.statsmapsnpix.com/2016/08/research-with-qgis-r-and-speaking-to.html(我指的是图20,靠近顶部 - 标签20042015是我想弄清楚如何创建)。R使用河流图的Sankey图 - 垂直标签

我该如何做到这一点?

这里是一个MWE,直接从包装中取出文件在https://cran.r-project.org/web/packages/riverplot/riverplot.pdf

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) 

在这里,我想有Node ANode B称为LeftNode C下另一个标签叫Right下一个标签。

回答

1

下面是做这件事:

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"))) 
(coords <- plot(r)) 
#   A B C 
# x  1 1 2 
# top -22 -10 -20 
# center -17 -5 -10 
# bottom -12 0 0 
text(
    x = range(coords["x",]), 
    y = min(coords["top",]), 
    labels = c("left", "right"), 
    pos = 1, offset = 0, font = 2 
) 

enter image description here