How to save plots one at a time from momentuHMM fit object?

21 Views Asked by At

I'm fitting different models with the R package momentuHMM. Once fitted, the HMM model can be visualized using the plot function (i.e. plot(fitHMM.object)) which produces a graph of the 1) step length distribution, 2) turning angle distribution, 3) graphs of the transition probabilities across different covariate combinations and 4) state-colored tracks. I can either have them plot one at a time and hit "enter" after each plot to get the next plot to appear or I can use the ask = FALSE argument and it will return all plots at once.

I want to save the plots and specify the name of the files but I don't want to manually have to save each one by clicking the save button in the plotting window nor do I want them all in one pdf - I want each plot to be its own separate png(). How do I specify which graph I want plotted (i.e. just the step length distribution) so I can save it using png() and dev.off()? I tried plot(fitHMM.object, ask = FALSE, plotTracks = FALSE, which = c(1,1)) like you would for plotting a regular lm object but no luck.

Thanks.

library(momentuHMM)

nbStates <- 2
stepDist <- "gamma"
angleDist <- "vm"

# Example data
data <- example$m$data

mu0 <- c(20,70)
sigma0 <- c(10,30)
kappa0 <- c(1,1)
stepPar <- c(mu0, sigma0) 
anglePar <- kappa0 
formula <- ~cov1+cos(cov2)

m <- fitHMM(data=data,
           nbStates=nbStates,
           dist=list(step=stepDist, angle=angleDist),
           Par0=list(step=stepPar,angle=anglePar),
           formula=formula)

print(m)

plot(m, breaks = 25, plotTracks = FALSE)

plot(m, breaks = 25, ask = FALSE, plotTracks = FALSE)

0

There are 0 best solutions below