Matrix specification for simple diagram, using 'diagram' package

449 Views Asked by At

I'm experiencing issues in correctly specifying a positions matrix for plotmat() from diagram package (technically, that's for different package (plspm), which uses plotmat() internally and allows to pass arguments to it). The diagram I'm trying to encode represents very simple graph, but I don't have experience working with graphs and, consequently, with their specification via matrix notation. Thank you for attention.

  A 
   \
    \
  B--D
    /
   /
  C

Here's what I've tried (among other attempts):

mat <- matrix(c(1, 1, 1, 2, 1, 3, 2, 2), ncol = 2)
plot.plspm(..., pos = mat)

P.S. Also would appreciate, if you could advise on how to control vertical positioning of elements A and C (distance from the B-D line), using plotmat().

UPDATE (for @jbaums):

enter image description here

1

There are 1 best solutions below

0
On

Finally, I have figured it out myself. It's a little tricky, but not a rocket science. Thanks to everyone who tried to help or, at least, read the question. Actually, after I've figured this out, I took another look at the @jbaums' suggestion above and realized that it is basically the same, discounting non-essential details. The suggested solution (which was appearing incorrectly, as shown above) was tested in my RStudio, whereas, since my machine with RStudio Server was down, I had to test my solution on R-Fiddle... The same company. Same (similar) technology. Go figure. Anyway, here is my obligatory minimal reproducible example (MRE):

library(diagram)

connect <- c(0,0,0,0,
             0,0,0,0,
             1,1,0,1,
             0,0,0,0)

M <- matrix(nrow=4, ncol=4, byrow=TRUE, data=connect)
p <- plotmat(M, pos=c(1, 2, 1), name='', box.col="lightblue", curve=0)

MRE result:

enter image description here