I want to draw a flow diagram for a compartmental model in R or Rstudio. After searching the the internet and this website I was able to partially achieve the following:
http://apprentiss.com/model_diagram/untitled2.png
My final goal is to achieve this: http://apprentiss.com/model_diagram/Untitled.png All arrows must be named with a letter.
and here is my current code for the diagram:
Thanks for your help
library(diagram)
M <- matrix(nrow = 4, ncol = 4, byrow = TRUE, data = 0)
C <- M
A <- M
M[2, 1] <- paste(expression(beta[0]))
M[3, 2] <- paste(expression(alpha))
M[4, 2] <- paste(expression(a[t]))
M[3, 4] <- paste(expression(rho))
M[1, 3] <- paste(expression(phi1))
C[2, 1] <- 0.0
C[3, 2] <- 0.0
C[4, 2] <- 0.0
C[3, 4] <- 0.0
C[1, 3] <- -0.07
A[2, 1] <- A[3, 2] <- A[3, 4] <- A[1, 3]<-A[4, 2]<-2
A[4, 1] <- 2
col <- M
col[] <- "black"
col[4, 2] <- "blue"
plotmat(M, pos = c(1,1,2), curve = C, name = c("S","C","R","I"),
box.size=c(0.05,0.05,0.05,0.05), box.prop = 1,
arr.lwd=A,my=0.0,mx= 0.0, dtext = c(0.6),arr.length= 0.4,shadow.size = 0,
lwd = 1, box.lwd = 2, box.cex = 1, cex.txt = 1,
arr.lcol = col, arr.col = col, box.type = "circle",
lend=4)
##======
With regard to the amount of time that has passed since this question was asked, I anticipate that @Lunik has resolved the issue in some other manner. Nevertheless, since I used this question as an exercise when I today wanted to investigate the
diagram
-package, I might as well post the solution I managed to put together.The main point in this solution is to add a bunch of extra nodes, that enables the specification of the additional arrows going out into "empty" areas. The trick is to "hide" these extra nodes such that they don't show up on the graphical representation, i.e. it's basically a question about selecting empty names
""
for the nodes that we don't want to see, and then select colours that makes them "invisible"In order to get a plot as similar as possible to the desired output, a solution with altogether 13 nodes were selected, where only 4 of them will be visible.