Milad - 2 months ago 8
LaTeX Question

# knitr adds an empty figure with ssplot from seqHMM package

I have the following chunk in RStudio:

<<sumfig,dependson='data',fig.cap="Summary of sequences">>=
ssplot(smult)
@


ssplot
is a function in
seqHMM
package which creates a frequency graph and
smult
is my sequence data.

When I run my code, I get two figures in my pdf: The first one is an empty white figure with label
{fig:sumfig1}
and the second one is the real figure with label
{fig:sumfig1}
. I have similar experience with other plots from this package. I also have some other graphs in my file from other packages which work just fine.

Is it something wrong with the package or I am doing something wrong?

The root of this issue seems to be seqHMM:ssplot, not knitr: Even in an interactive sesion, ssplot generates two plots, an empty one and the actual plot.

If there is only one plot generated in the chunk with ssplot, the chunk option fig.keep = "last" can be used to disregard the first plot and show only the second (last) one.

\documentclass{article}
\begin{document}

<<echo = FALSE, message = FALSE, fig.keep = "last">>=
library(seqHMM)

# from ?ssplot
data("biofam3c")

# Creating sequence objects
child_seq <- seqdef(biofam3c$children, start = 15) marr_seq <- seqdef(biofam3c$married, start = 15)
left_seq <- seqdef(biofam3c\$left, start = 15)

## Choosing colors
attr(child_seq, "cpal") <- c("#66C2A5", "#FC8D62")
attr(marr_seq, "cpal") <- c("#AB82FF", "#E6AB02", "#E7298A")
attr(left_seq, "cpal") <- c("#A6CEE3", "#E31A1C")

# Plotting state distribution plots of observations
ssplot(list("Children" = child_seq, "Marriage" = marr_seq,
"Residence" = left_seq))
@

\end{document}