plots a graph (network), based on a transition matrix
Description
visualises a transition matrix as a number of (labeled) boxes connected by (labeled) arrows.
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  plotmat(A, pos = NULL, curve = NULL, name = NULL, absent = 0,
relsize = 1, lwd = 2, lcol = "black", box.size = 0.1,
box.type = "circle", box.prop = 1, box.col = "white",
box.lcol = lcol, box.lwd = lwd,
shadow.size = 0.01, shadow.col = "grey", dr = 0.01,
dtext = 0.3, self.lwd = 1, self.cex = 1,
self.shiftx = box.size, self.shifty = NULL,
self.arrpos = NULL, arr.lwd = lwd, arr.lcol = lcol,
arr.col = "black", arr.type = "curved", arr.pos = 0.5,
arr.length = 0.4, arr.width = arr.length/2,
endhead = FALSE, mx = 0.0, my = 0.0, box.cex = 1,
txt.col = "black", txt.xadj = 0.5, txt.yadj = 0.5,
txt.font = 1, prefix = "", cex = 1, cex.txt = cex,
add = FALSE, main = "", cex.main = cex,
segment.from = 0, segment.to = 1, latex = FALSE, ...)

Arguments
A 
square coefficient matrix, specifying the links (rows=to, cols=from). 
pos 
vector, specifying the number of elements in each graph row, or a 2column matrix with element position, or NULL. If a 2column matrix, the values should be withing 0 and 1. 
curve 
one value, or a matrix, same dimensions as 
name 
string vector, specifying the names of elements, dimension =
number of rows (columns) of 
absent 
all elements in 
relsize 
scaling factor for size of the graph. 
lwd 
default line width of arrow and box. 
lcol 
default color of arrow line and box line. 
box.size 
size of label box, one value or a vector with dimension =
number of rows of 
box.type 
shape of label box (rect, ellipse, diamond, round, hexa,
multi), one value or a vector with dimension=number of rows of 
box.prop 
length/width ratio of label box, one value or a vector
with dimension=number of rows of 
box.col 
fill color of label box, one value or a vector with
dimension=number of rows of 
box.lcol 
line color of label box, one value or a vector with
dimension=number of rows of 
box.lwd 
line width of the box, one value or a vector with dimension
= number of rows of 
shadow.size 
relative size of shadow of label box, one value or a
vector with dimension=number of rows of 
shadow.col 
color of shadow of label box, one value or a vector with
dimension=number of rows of 
dr 
size of segments, in radians, to draw ellipse (decrease for smoother ellipses). 
dtext 
controls the position of arrow text relative to arrowhead. 
self.lwd 
line width of selfarrow, (arrow from i to i), one value or
a vector with dimension=number of rows of 
self.cex 
relative size of selfarrow, relative to box, one value or
a vector with dimension=number of rows of 
self.shiftx 
relative shift of selfarrow, in xdirection, one value
or a vector with dimension=number of rows of 
self.shifty 
relative shift of selfarrow, in ydirection, one value
or a vector with dimension=number of rows of 
self.arrpos 
position of the selfarrow, angle in radians relative to
xdirection, one value or a vector with dimension=number of rows of

arr.lwd 
line width of arrow, connecting two different points, one
value, or a matrix with same dimensions as 
arr.lcol 
color of arrow line, one value, or a matrix with same
dimensions as 
arr.col 
color of arrowhead, one value, or a matrix with same
dimensions as 
arr.type 
type of arrowhead, one of ("curved", "triangle",
"circle", "ellipse", "T", "simple"), one
value, or a matrix with same dimensions as 
arr.pos 
relative position of arrowhead on arrow segment/curve, one
value, or a matrix with same dimensions as 
arr.length 
arrow length, one value, or a matrix with same
dimensions as 
arr.width 
arrow width, one value, or a matrix with same dimensions
as 
endhead 
if TRUE: the arrow line stops at the arrowhead; default =

mx 
horizontal shift of the boxes. 
my 
vertical shift of the boxes. 
box.cex 
relative size of text in boxes, one value or a vector with
dimension=number of rows of 
txt.col 
color of text in boxes, one value or a vector with
dimension=number of rows of 
txt.xadj, txt.yadj 
the x and y adjustment of the labels in the boxes,
one value or a vector with dimension=number of rows of 
txt.font 
the font to be used for the text in boxes,
one value or a vector with dimension=number of rows of 
prefix 
to be added in front of nonzero arrow labels. 
cex 
relative size of text. 
cex.txt 
relative size of arrow text, one value, or a matrix with
same dimensions as 
add 
start a new plot ( 
main 
main title. Only effective if 
cex.main 
relative size of main title. 
segment.from 
if not 
segment.to 
if not 
latex 
if 
... 
other arguments passed to function 
Details
The square transition matrix A
determines the number of elements
of A
(rows of A
) and which elements are connected
(all values in A
different from absent
).
A
also provides the values of arrowlabels.
The position of the elements are specified with pos
, which is
either NULL
,
or a vector specifying the number of elements on a row, or a 2columned
matrix specifying the (x,y) position of each element.
The ordering of elements is according to the row number of A
when
pos
isNULL
, the elements will be arranged on a circlewhen
pos
is a vector, it specifies the number of elements in each row. For instance, withpos = c(3,2,1)
the elements will be arranged in 3 rows (length of vector); on top row, 3 elements; on second row 2, and on third row 1 element will be positioned. All elements within a row are equally distributed horizontally, all rows are equally distributed vertically.when
pos
is a matrix, it specifies the x (1st column) and y (2nd column) position of each element.
The offset from xaxis and from yaxis can be changed with mx
and
my
.
The name of each element is given by vector name
; this name is
written in its respective box.
The relative size of this text can be changed by box.cex
.
By default, a shadow is drawn, in the rightlower corner of the box.
The shadow color and relative size is specified with shadow.col
and
shadow.size
respectively.
both can be one value (equal shadows) or a vector, specifying one value for each box shadow.
shadow.size = 0
toggles off the drawing of the shadow.
The type of the box is set with "box.type" which can take on the values:
"rect": a rectangle,
"ellipse": an ellipse,
"diamond": a diamond,
"round": a rectangle with rounded left and right edges,
"hexa": a hexagonal shape,
"multi": a multigonal shape.
"none" if no box is to be drawn.
The length of the box is set with box.size
, the proportionality
(length/width) ratio with box.prop
.
The fillcolor of the box is specified with box.col
;
the line width of the box with box.lwd
and the line color with
box.lcol
;
All box properties can be either one value (equal boxes) or a vector, specifying one value for each box.
For all values A[i,j] of A
which are not equal to absent
,
one arrow is drawn *from* columnelement j *to* the rowelement i of A
.
The curvature of this arrow is specified with matrix element curve[i,j],
where 'curve' is either NULL, one value, or has the same dimension as A
.
A straight arrow has curvature 0, NA
(the default) chooses a default
curvature,
Positive or negative values of curve
draws curved arrows.
If the arrow is curved, then dr
is the increment used to draw the
ellipse; set to a lower value for smoother lines.
The type of the arrowhead is set with arr.type
which can take the
values:
"simple" : uses comparable R function arrows
"triangle": uses filled triangle
"curved" : draws arrowhead with curved edges
"circle" : draws circular head
"ellipse" : draws ellepsoid head
"T" : draws Tshaped (blunt) head
The line color and width of the arrow line is set with arr.lcol
and
arr.lwd
The size of the arrow head is specified with arr.length
and
arr.width
,
the position of the arrow head is specified with arr.pos
(value
between [0,1]).
see Arrowhead
for details on arrow head
Value
a list containing:
arr 
a data.frame with arrow information:
. 
comp 
a matrix with the element position (centre of the boxes). 
radii 
the radiusses in x and ydirection of the boxes. 
rect 
the "xleft","ybot","xright",and "ytop" of the boxes  redundant. 
Author(s)
Karline Soetaert <karline.soetaert@nioz.nl>
See Also
shadowbox
,
Arrowhead
from package shape
try: demo(plotmat)
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92  M < matrix(nrow = 4, ncol = 4, byrow = TRUE, data = 0)
pp < plotmat(M, pos = c(1, 2, 1), name = c("A", "B", "C", "D"),
lwd = 1, box.lwd = 2, cex.txt = 0.8,
box.size = 0.1, box.type = "square", box.prop = 0.5,
main = "plotmat")
pp
# when explicitly given, pos should should be inbetween 0, 1
pos < cbind (c(0.2, 0.4, 0.6, 0.8), c(0.8, 0.6, 0.4, 0.2))
pp < plotmat(M, pos = pos, name = c("A", "B", "C", "D"),
lwd = 1, box.lwd = 2, cex.txt = 0.8,
box.size = 0.1, box.type = "square", box.prop = 0.5,
main = "plotmat")
# includes arrows between boxes
pm < par(mfrow = c(2, 2))
M < matrix(nrow = 4, ncol = 4, byrow = TRUE, data = 0)
M[2, 1] < M[3, 1] < M[4, 2] < M[4, 3] < "f1"
col < M
col[] < "red"
col[2, 1] < col[3, 1] < "blue"
pp < plotmat(M, pos = c(1, 2, 1), curve = 0, name = 1:4,
lwd = 1, box.lwd = 2, box.cex = 1:4, cex.txt = 0.8,
arr.lcol = col, arr.col = col, box.type = "circle",
box.prop = 1.0, main = "plotmat")
pp < plotmat(M, pos = c(1, 2, 1), curve = 0, name = 1:4,
lwd = 1, box.lwd = 2, box.cex = 1:4, cex.txt = 0.8,
arr.lcol = col, arr.col = col, box.type = "circle",
box.prop = 1.0, arr.len = 0.3,
segment.from = 0.35, segment.to = 0.65)
M[1, 2] < M[1, 3] < M[2, 4] < M[3, 4] < "f2"
pp < plotmat(M, pos = c(1, 2, 1), curve = 0.1, name = 1:4,
lwd = 1, box.lwd = 2, box.cex = 1:4, cex.txt = 0.8,
arr.lcol = col, arr.col = col, box.type = "none",
box.prop = 1.0, main = "plotmat", arr.len = 0.2,
segment.from = 0.3, segment.to = 0.7)
pp < plotmat(M, pos = c(1, 2, 1), curve = 0.1, name = 1:4,
box.lwd = 2, box.cex = 1:4, cex.txt = 0.8,
arr.lcol = col, arr.col = col, arr.pos = 0.7,
arr.type = "simple", lwd = 2, box.type = "none",
box.prop = 1.0, main = "plotmat", arr.len = 0.2,
segment.from = 0.3, segment.to = 0.7)
par(mfrow=pm)
# self arrows
diag(M) < "self"
pp < plotmat(M, pos = c(2, 2), curve = 0, name = LETTERS[1:4],
lwd = 1, box.lwd = 2, cex.txt = 0.8, self.cex = 0.5,
self.shiftx = c(0.1, 0.1, 0.1, 0.1),
box.type = "diamond", box.prop = 0.5, main = "plotmat")
M < matrix(nrow = 4, ncol = 4, data = 0)
M[2, 1]< 1 ; M[4, 2] < 2 ; M[3, 4] < 3; M[1, 3] < 4
pp < plotmat(M, pos = c(1, 2, 1), curve = 0.2, name = letters[1:4],
lwd = 1, box.lwd = 2, cex.txt = 0.8, arr.type = "triangle",
box.size = 0.1, box.type = "hexa", box.prop = 0.5,
main = "plotmat")
arrlwd < M*2
arr.length < M*0.4
cextxt < M*0.8
plotmat(M, pos = c(1, 2, 1), curve = 0.2, name = letters[1:4], lwd = 1,
box.lwd = 2, arr.type = "triangle", box.size = 0.1,
box.type = "hexa", box.prop = 0.5, main = "plotmat",
arr.lwd = arrlwd, arr.length = arr.length, cex.txt = cextxt,
txt.font = 1:4, txt.xadj = seq(3, 3, length.out = 4),
txt.yadj = 1)
M < matrix(nrow = 4, ncol = 4, byrow = TRUE, data = 0)
M < as.data.frame(M)
M[[2,1]]< "k[si]"
M[[3,1]]< "k[N]"
M[[4,2]]< "sqrt(frac(2,3))"
names <
c(expression(lambda[12]), "?",
expression(lambda[13]),expression(lambda[23]))
plotmat(M, pos = c(1, 2, 1), name = names, lwd = 1, box.lwd = 2,
curve = 0, cex.txt = 0.8, box.size = 0.1, box.type = "square",
box.prop = 0.5, main = "plotmat")
plotmat(M, name = letters[1:4], curve = 0, box.cex = 1:4, box.lwd = 4:1,
box.size = 0.075, arr.pos = 0.7,
box.col = c("lightblue", "green", "yellow", "orange"))
