Milad Milad - 8 months ago 47
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">>=

is a function in
package which creates a frequency graph and
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
and the second one is the real figure with label
. 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.


<<echo = FALSE, message = FALSE, fig.keep = "last">>=

# from ?ssplot

# 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))