简体   繁体   中英

R: Drawing markov model with diagram package (making diagram changes)

I have the following code that draws a transition probability graph using the package heemod (for the matrix) and the package diagram (for drawing). The following code generates such a graph with data that I have generated:

library('heemod')
library('diagram')
mat_dim <- define_transition(
state_names = c('State_A', 'State_B', 'State_C'),
  .18, .73, .09, 
  .12, .10, .78,
  .58, .08, .33);
plot(mat_dim)

This creates the following plot:

在此处输入图片说明

My questions all originate from my poor understanding of the diagram package and I can't figure out these seemingly simple adaptations...

How can I move the arrow at State_B around (eg90 degrees to one side) so that it does not overlap with other arrows? Is there a simple way to move the states closer together?

See ?plotmat .

  • argument curve , a matrix, to control the curvatures of the "non-self" transitions
  • arguments self.shiftx and self.shifty to control the positions of the self-transitions
  • argument self.arrpos to control the positions of the self-arrows

This is really not easy. Here is what I obtained by a lot of trial-errors.

curves <- matrix(nrow = 3, ncol = 3, 0.05)
plot(mat_dim, 
     curve=curves, 
     self.shiftx = c(0.1,-0.1,0), 
     self.shifty = c(-0.1,-0.1,0.15), 
     self.arrpos = c(1,2.1,1))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM