diff options
Diffstat (limited to 'R/get_plot_info.R')
-rw-r--r-- | R/get_plot_info.R | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/R/get_plot_info.R b/R/get_plot_info.R index 86d4389..e3220ff 100644 --- a/R/get_plot_info.R +++ b/R/get_plot_info.R @@ -1,6 +1,8 @@ #General function for setting up plots -get_plot_info <- function(x, parameters, per_plot, ask, Rhat_min=NULL){ +# Called by densityplot, traceplot, and plot.jagsUI +# plot.jagsUI only uses the 'params' component in the output, ignores the rest +get_plot_info <- function(x, parameters, layout, ask, Rhat_min=NULL){ #Expand non-scalar parameters and check they exist all_params <- param_names(x$samples) @@ -23,16 +25,24 @@ get_plot_info <- function(x, parameters, per_plot, ask, Rhat_min=NULL){ if(length(parameters)==0) stop("No parameters > Rhat_min") } - #Reduce max panels per plot if larger than number of parameters - if(length(parameters) <= per_plot){ - per_plot <- length(parameters) - ask=FALSE + # Fix 'layout' + if(is.null(layout)) { + if(length(parameters) <= 9){ + per_plot0 <- length(parameters) + ask <- FALSE + layout <- c(ceiling(sqrt(per_plot0)), round(sqrt(per_plot0))) + } else { + layout <- c(3,3) + } + } else if(length(layout) != 2) { + layout <- rep(layout[1], 2) } - + per_plot <- prod(layout) + #Set up new par settings new_par <- list(mar=c(1.5,1.5,2.5,1), oma=c(3,3,0,0), ask=ask) if(per_plot > 1) - new_par$mfrow <- c(ceiling(sqrt(per_plot)), round(sqrt(per_plot))) + new_par$mfrow <- layout list(params=parameters, new_par=new_par, per_plot=per_plot) } |