R markov链包,可以设置节点的坐标和大小吗? [英] R markov chain package, is possible to set the coordinates and size of the nodes?

查看:113
本文介绍了R markov链包,可以设置节点的坐标和大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究某些生物学行为问题,并且我有一个过渡矩阵,希望以某种方式绘制.

I'm working with R in some biology-behavioural problems, and I have a transition matrix which I want to plot in a certain way.

我正在使用markovchain程序包,这使可视化变得容易.

I'm using the markovchain package, which makes easy the visualization.

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

This is a test-code and it's output.

> 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)

问题是,我想设置图形节点的坐标以将其放置在2D网格或类似的网格中,还希望设置节点的大小. 我知道此程序包可与S4一起使用,但我并不十分熟悉它,也不知道是否有任何对我有用的参数. 有帮助吗?

The thing is, I would like to set the coordinates of the graph nodes to place them in a 2D grid or something like that, and also to set the size of the nodes. I know that this package works with S4, but I'm not really familiar with it and don't know if there are any arguments that would be useful to me. Any help?

推荐答案

您可以执行以下操作:

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软件包中受益.

The layout is a matrix of two columns. Each row contains coordinates per node. With vertex.size, you can adjust the size of the nodes. Note that markovchain package benefits from the igraph package to do so.

使用这些布局

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)

您将拥有:

这篇关于R markov链包,可以设置节点的坐标和大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆