kenkellner / jagsUI

R package to Run JAGS (Just Another Gibbs Sampler) analyses from within R
https://kenkellner.github.io/jagsUI/
35 stars 7 forks source link

traceplot and densityplot get layout argument #46

Closed mikemeredith closed 3 years ago

mikemeredith commented 3 years ago

Replace the per_plot argument in traceplot and densityplot with layout, a length 2 vector specifying the number of rows and columns in the plot. (If a single value is provided, this is used for rows and columns.) The default is 3 x 3, the same as the old per_plot=9 default, reduced if there are fewer parameters.

The plot.jagsUI method keeps the per_plot argument, which is effectively the number of rows, the number of columns being fixed at 2.

Tested with output from Schaub & Kéry (in prep) in R 4.1.0 and R-devel.

mikemeredith commented 3 years ago

Oops, a bug: with layout=c(1,1) or just 1 parameter, the functions should not touch par(mfrow...), so this code should work to produce histogram and density plot side by side:

par(mfrow=c(1,2))
hist(out$sims.list$foo)
densityplot(out, "foo")

... but it doesn't do that. I'll chase that up now.

mikemeredith commented 3 years ago

That was a pre-existing bug, not connected to the new layout argument. The call to par(oma=...) causes the next plot to go top-left. I'll do a new pull request with the fix.

mikemeredith commented 3 years ago

That now works. Try this:

example(jags)
par(mfrow=1:2)
scatter.smooth(employed ~ gnp)
abline(lm(employed ~ gnp), col='red')
densityplot(out, "beta")

traceplot instead of densityplot also works.

kenkellner commented 3 years ago

Thanks Mike, looks good.