如何在R中的节点图中编写自我箭头?

时间:2016-10-11 16:17:39

标签: r graphics figures

我找到的代码创建了一个种群矩阵节点图。我想做的就是在最后一个节点上添加一个自我箭头,即一个指向自身的箭头。希望你能帮忙。

library(diagram)

Numgenerations <- 6
DiffMat <- matrix(data = 0, nrow = Numgenerations, ncol = Numgenerations)
AA <- as.data.frame(DiffMat)
AA[[1,5]] <- "f[4]"
AA[[1,6]] <- "f[5]"
#
AA[[2,1]] <- "s[list(0,1)]"
AA[[3,2]] <- "s[list(1,2)]"
AA[[4,3]] <- "s[list(2,3)]"
AA[[5,4]] <- "s[list(3,4)]"
AA[[6,5]] <- "s[list(4,5)]"

#
name <- c(expression(Age[0]), expression(Age[1]), expression(Age[2]),
      expression(Age[3]), expression(Age[4]), expression(Age[5]))
#
plotmat(A = AA, pos = 6, curve = 0.7, name = name, lwd = 2,
    arr.len = 0.6, arr.width = 0.25, my = -0.2,
    box.size = 0.05, arr.type = "triangle", dtext = 0.95,
    main = "Age-structured population model")

1 个答案:

答案 0 :(得分:1)

您可以这样添加箭头:

AA[[6,6]] <- "s[list(5,5)]"

或者,如果您希望将其标记为自我箭头,

AA[[6,6]] <- "self"

我需要将relsize设置为略小于1,以防止自我箭头在右边缘被剪裁。

plotmat(A = AA, pos = 6, curve = 0.7, name = name, lwd = 2,
        arr.len = 0.6, arr.width = 0.25, my = -0.2,
        box.size = 0.05, arr.type = "triangle", dtext = 0.95,
        main = "Age-structured population model",
        relsize=0.97) 

enter image description here