0

我正在尝试绘制如下图:

library(diagram)
Numgenerations <- 6
DiffMat <- matrix(data = 0, nrow = Numgenerations, ncol = Numgenerations)
AA <- DiffMat
AA[1,4] <- "f[3"
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")

然后,R 将 "f[3" 视为公式并返回

Error in parse(text = txt) : <text>:2:0: unexpected end of input
1: f[3
  ^

我查看了带有包装的小插曲。在第 2.3 节中,它写道:

下一个示例使用公式来标记箭头 1 。这是通过将 data.frame 而不是矩阵传递给函数来完成的plotmat

但是,我plotmat在前面的示例中传递的是矩阵而不是 data.frame。现在我找不到在绘制标签之前避免parsein的方法。plotmat

图表包的版本是1.6。

有人可以帮我吗?谢谢。

4

1 回答 1

3

您需要将 f[3 放在双引号中,如下所示:

library(diagram)
Numgenerations <- 6
DiffMat <- matrix(data = 0, nrow = Numgenerations, ncol = Numgenerations)
AA <- as.matrix(DiffMat)
AA[1,4] <- "'f[3'" #double then single quotes
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")

在此处输入图像描述

于 2013-03-11T10:17:50.057 回答