data(mvad)
## Defining a state sequence object
mvad.seq <- seqdef(mvad[, 17:86])
## Computing dissimilarities
mvad.lcs <- seqdist(mvad.seq, method="LCS")
dt <- disstree(mvad.lcs~ male + Grammar + funemp + gcse5eq + fmpr + livboth,
data=mvad, R = 10)
print(dt)
## Using simplified interface to generate a file for GraphViz
seqtree2dot(dt, "mvadseqtree", seqdata=mvad.seq, type="d",
border=NA, withlegend=FALSE, axes=FALSE, ylab="", yaxis=FALSE)
## Generating a file for GraphViz
disstree2dot(dt, "mvadtree", imagefunc=seqdplot, imagedata=mvad.seq,
## Additional parameters passed to seqdplot
withlegend=FALSE, axes=FALSE, ylab="")
## Second method, using a specific function
myplotfunction <- function(individuals, seqs, mds,...) {
par(font.sub=2, mar=c(3,0,6,0), mgp=c(0,0,0))
## using mds to order sequence in seqiplot
mds <- cmdscale(seqdist(seqs[individuals,], method="LCS"),k=1)
seqiplot(seqs[individuals,], sortv=mds,...)
}
## Generating a file for GraphViz
## If imagedata is not set, index of individuals are sent to imagefunc
disstree2dot(dt, "mvadtree", imagefunc=myplotfunction, title.cex=3,
## additional parameters passed to myplotfunction
seqs=mvad.seq, mds=mvad.mds,
## additional parameters passed to seqiplot (through myplotfunction)
withlegend=FALSE, axes=FALSE,tlim=0,space=0, ylab="", border=NA)
## To run GraphViz (dot) from R and generate an "svg" file
## shell("dot -Tsvg -O mvadtree.dot")
Run the code above in your browser using DataLab