R马尔可夫链包,是否可以设置节点的坐标和大小?

R markov chain package, is possible to set the coordinates and size of the nodes?

我正在使用 R 解决一些生物学行为问题,我有一个转换矩阵,我想以某种方式绘制它。

我正在使用 markovchain 包,它使可视化变得容易。

这是一个测试代码,它是输出。

> a<-array(0.25,dim = c(4,4))
> markov<-new("markovchain",transitionMatrix=a,states=c("a","b","c","d"), name="test")
> markov
test 
 A  4 - dimensional discrete Markov Chain defined by the following states: 
 a, b, c, d 
 The transition matrix  (by rows)  is defined as follows: 
 a    b    c    d
 a 0.25 0.25 0.25 0.25
 b 0.25 0.25 0.25 0.25
 c 0.25 0.25 0.25 0.25
 d 0.25 0.25 0.25 0.25

 > plot(markov)

问题是,我想设置图形节点的坐标以将它们放置在二维网格或类似的东西中,并设置节点的大小。 我知道这个包适用于 S4,但我不是很熟悉它,也不知道是否有任何对我有用的参数。 有帮助吗?

你可以这样做:

layout <- matrix(c(0,0,0,1,1,1,1,0), ncol = 2, byrow = TRUE)

     # [,1] [,2]
# [1,]    0    0
# [2,]    0    1
# [3,]    1    1
# [4,]    1    0

plot(markov, vertex.size = 25, layout = layout)

layout是一个两列矩阵。每行包含每个节点的坐标。使用vertex.size,您可以调整节点的大小。请注意,markovchain 包受益于 igraph 包。

有了这些布局

layout <- matrix(c(4,-2,7,2,8,8,8,-4), ncol = 2, byrow = TRUE)
     # [,1] [,2]
# [1,]    4   -2
# [2,]    7    2
# [3,]    8    8
# [4,]    8   -4

plot(markov, vertex.size = 25, layout = layout)

你会得到这个: